Connecting to GitHub with SS
一 About SSH
二 Checking for existing SSH keys
$ ls -al ~/.ssh
$ ssh-add -l // 可以通过 ssh-add -l 来确私钥列表
可以通过 ssh-add -D 来清空私钥列表
$ ssh-add -D
三 Generating a new SSH key and adding it to the ssh-agent
3.1 Generating a new SSH key
$ ssh-keygen -t rsa -b 4096 -C “your_email@example.com“
Generating public/private rsa key pair.
Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter]
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
默认在 /c/users/administartor/.ssh/…
id_rsa:
id_rsa.pub: ssh-rsa AAAAB3NzaC1yc2E…
known_hosts:github添加成功后会写入:github.com,13.229.188.59 ssh-rsa AAAAB3NzaC1yc…
3.2 Adding your SSH key to the ssh-agent
$ eval $(ssh-agent -s)
$ ssh-add ~/.ssh/id_rsa
$PS: 如果多添加了没关系,反正关掉之后都没有了。需要重新启动ssh-agent, 执行ssh-add ~/.ssh/*/id_rsa
四 Adding a new SSH key to your GitHub account
$ clip < ~/.ssh/id_rsa.pub
然后去github/gitblit等git服务器添加SSH key
五 Testing your SSH connection
$ ssh -T git@github.com
The authenticity of host ‘github.com (IP ADDRESS)’ can’t be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)?
Hi username! You’ve successfully authenticated, but GitHub does not provide shell access.
六 Working with SSH key passphrases
其他
## $_PS ssh-keygen删除旧密钥
linux 系统上使用ssh工具远程登录设备时,如果之前保存过该设备的密钥,之后该设备密钥更新,此时需执行以下命令才能后续的ssh正常登录。
ssh-keygen -f “/root/.ssh/known_hosts” -R 192.168.0.1
其中 -f filename 指定密钥文件名。
-R hostname 从 known_hosts 文件中删除所有属于 hostname 的密钥。