[root@localhost ~]# ssh-keygen -t rsa -C "xxxxxxx@yyy.com" Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. 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:...... xxx@yyy.com The key's randomart image is: ......
查看公钥
进入上面命令生成秘钥的路径(Your public key has been saved in /root/.ssh/id_rsa.pub.):
打开浏览器,登录github网站,然后点击右上角的头像的后面的三角按钮,选择Settings,然后点击SSH and GPG keys,点击SSH keys横栏右侧的New SSH key按钮。输入各个公钥的名称,我这里为CentoSOnLinuxDeploy。然后输入公钥,点击Add SSH key按钮。此时可能会要求输入密码,按提示输入密码即可。
测试是否能够连接
回到Xshell,输入如下命令测试连接,然后输入yes回车。
1
ssh -T git@github.com
ssh连接成功效果:
1 2 3 4 5 6 7 8
[root@localhost .ssh]# ssh -T git@github.com The authenticity of host 'github.com (52.74.223.119)' can't be established. RSA key fingerprint is SHA256:nThbg6kXUpJjskgjghJhshsuiwoJkARLviKwJuhnb8. RSA key fingerprint is MD5:23:45:rt:2g:56:31:7u:89:sd:3h:56::eb:df:a6:48. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts. Hi xxx! You've successfully authenticated, but GitHub does not provide shell access. [root@localhost .ssh]#