How to set up SSH keys for Github on Centos

Creating SSH keys on CentOS 

The chances are that you already have an SSH key pair on your CentOS client machine. If you are generating a new key pair, the old one will be overwritten.

Run the following ls command to check whether the key files exist:

[root@oracle-db-19c ~]# ls -l ~/.ssh/id_*.pub
ls: cannot access '/root/.ssh/id_*.pub': No such file or directory
[root@oracle-db-19c ~]# 

If the output of the command returns something like No such file or directory, or no matches found it means that the user does not have SSH keys, and you can proceed with the next step and generate SSH key pair.

Otherwise, if you have an SSH key pair, you can either use those or backup up the old keys and generate new ones.

[root@oracle-db-19c ~]# git config --global user.name "psmaxwell"
[root@oracle-db-19c ~]# git config --global user.email "xxxxxxxxxxx@qq.com" 
[root@oracle-db-19c golang_projects]# 
[root@oracle-db-19c golang_projects]# git version
git version 2.39.0
[root@oracle-db-19c golang_projects]# git config --list
user.name=psmaxwell
user.email=xxxxxxxxxxxxx@qq.com
init.defaultbranch=main
safe.directory=/home/maxwell/projects/golang_projects
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
[root@oracle-db-19c golang_projects]# ssh-keygen -t rsa -C "xxxxxxxxxxxxx@qq.com"        
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Passphrases do not match.  Try again.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:DHZt+qho/u0LlfWkBCeok50h+/S8xN1dzx6nOxlbXUw xxxxxxxxxxxxxxxx@qq.com
The key's randomart image is:'
+---[RSA 3072]----+
|       .o .      |
|    . o  =      E|
|     *oo. = .  o |
|    =.++ * +    +|
|     + +S..... o+|
|      ..=o. . o.*|
|      .....    Bo|
|    .. +.     = .|
|   oo.o.+.    .o |
+----[SHA256]-----+
[root@oracle-db-19c golang_projects]# cd /root/.ssh/
[root@oracle-db-19c .ssh]# ls -ltr
total 8
-rw-------. 1 root root 2655 Jan 15 17:32 id_rsa
-rw-r--r--. 1 root root  570 Jan 15 17:32 id_rsa.pub
[root@oracle-db-19c .ssh]# cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC9yxcBz9gGBTh/lNRI42wbD7AqdGI3bWdh25SIKhYZVTe4TKoMtx2cWsQPLTp7R98Wf6obIRCtA5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxQ7lXPHKaTG9Qi8vEg6FY5LgQULr6AKLQSRdksS05rHYZNhs5ZsHVgDsyMlSiA8LA54iHJYuPohcsyxj4IdnRWij5kjYuNmZM9HuAkvO4zOZD5wR4jCaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxojFgeD+DrVPlvW9K5QL+LPWA7YMIhPw33OPpDsKDWoGROiazKGx6nzEaty1pw6YoxOmvlCk= xxxxxxxxxxxxxxxxxx@qq.com
[root@oracle-db-19c .ssh]#

[root@oracle-db-19c maxwell]# cd projects/
[root@oracle-db-19c projects]# ls -ltr
total 0
drwxrwxr-x. 4 maxwell maxwell 70 Jan 15 16:48 golang_projects
[root@oracle-db-19c projects]# cd golang_projects/
[root@oracle-db-19c golang_projects]# ls -ltr
total 4
drwxrwxr-x. 16 maxwell maxwell 4096 Jan 15 14:44 maxwell_the_go_programming_language_projects
[root@oracle-db-19c golang_projects]# git clone git@github.com:psmaxwell/awesome_golang_project1_the_go_programming_language.git
Cloning into 'awesome_golang_project1_the_go_programming_language'...
Enter passphrase for key '/root/.ssh/id_rsa': 
warning: You appear to have cloned an empty repository.
[root@oracle-db-19c golang_projects]# ls -ltr
total 4
drwxrwxr-x. 16 maxwell maxwell 4096 Jan 15 14:44 maxwell_the_go_programming_language_projects
drwxr-xr-x.  3 root    root      18 Jan 15 17:36 awesome_golang_project1_the_go_programming_language
[root@oracle-db-19c golang_projects]#
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值