[root@localhost ~]# ssh-keygen -t rsa <== 建立密钥对,-t代表类型,有RSA和DSA两种 Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): <==密钥文件默认存放位置,按Enter即可 Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase): <== 输入密钥锁码,或直接按 Enter 留空 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:K1qy928tkk1FUuzQtlZK+poeS67vIgPvHw9lQ+KNuZ4 root@localhost.localdomain The key's randomart image is: +---[RSA 2048]----+ | +. | | o * . | | . .O + | | . *. * | | S =+ | | . =... | | .oo =+o+ | | ==o+B*o. | | oo.=EXO. | +----[SHA256]-----+
(2)添加到github个人配置中
1. 登录GitHub,进入你的Settings
2. 左侧点击SSH and GPG keys
3. 创建New SSH key
4. 填入rsa.pub
复制rsa.pub内容到Key中,Title任起,方便自己辨识即可。
(3)测试
1
ssh -T git@github.com
第一次连接会提示建立连接,输入yes即可,正常情况下你会得到通过验证的提示。如下:
1 2
dwh@dwhsarch ~> ssh -T git@github.com Hi DingWH03! You've successfully authenticated, but GitHub does not provide shell access.