目录

输入ssh-keygen,连续按提示enter

# ssh-keygen
...
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:WHxfDWlBLpVUBZvwdzCc95XdmYYPcW6eKqrL3AjTY40 root@linux
The key's randomart image is:
+---[RSA 2048]----+
|            .=%@B|
|       .     BX@=|
|        o . ..X+*|
|       o . . ooo+|
|      . S   .  o |
|        .  |
|     o E . . .   |
|      * + . .    |
|       *oo       |
+----[SHA256]-----+

输入ls ~/.sshid_rsa.pub是公钥, id_rsa是私钥

# ls ~/.ssh
id_rsa  id_rsa.pub 

读取公钥信息

 # cat  ~/.ssh/id_rsa.pub
...
ssh-rsa AAAAB3NzaC1yc2EAAAADAQSBAAABAQDS93Az7KYTrLYUVWlB28X7T8LDy2Ja1ehS6QP7IH2fjZXQXw+zAUyAZOgiD2oC9Xr6cNaU2hv3kBgZlor250A+E8ZHPFWXW5UeCkeEmqQ579qHBKA6V0jBOY5X8Tr1mqEQYEg8XgsUiQYWCtB4fQcU4/kzcuod+Qb52tRc4KY2WkDEJzJXCTR2Kxhm1u5m2LqucAB9N8REPhtBV3IiEhWyAYTKELQEN4ipBwOcJdLAkYfArXeCMRX/ueXob10Eo0lTtBZDl07QxQje2E0fthQpO6Gp4xzXQ86l13BK3aHR2rlB7e1iPzFqIxP7JObrr/Me8AE1L3WhfYa5zUSvQcyv root@linux

进入github设置页面,title任意填写,key中填写上面复制的内容。

测试,先有警告,继续enter,会显示successfully即表示成功。

# ssh -T git@github.com
...
The authenticity of host 'github.com (192.30.253.113)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
RSA key fingerprint is MD5:16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.253.113' (RSA) to the list of known hosts.
Hi username! You've successfully authenticated, but GitHub does not provide shell access.