# 1. 打开本地终端# 注意:邮箱必须是注册 github 用的邮箱
ssh-keygen -t rsa -C "github@xx.com"# 返回如下内容
Generating public/private rsa key pair.
Enter fileinwhich to save the key (/root/.ssh/id_rsa): /root/.ssh/id_rsa
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
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:T87*************On5 github@xx.com
# 返回内容结束# github 上用到的是公钥 id_rsa.publs
id_rsa id_rsa.pub known_hosts
# 查看 id_rsa.pubcat id_rsa.pub
# 拷贝 id_rsa.pub 中的内容如下
ssh-rsa AAAA**************************ERf github@xx.com
# 2. 登录 github 官网,右上角头像点击,选择 settings - SSH and GPG keys# 到达页面:https://github.com/settings/keys,点击 new SSH key# key 填写之前本地 id_rsa.pub 里的内容
ssh-rsa AAAA**************************ERf github@xx.com
# 3. 测试本地和 github 是否连通ssh -T git@github.com
Hi hualaoshuan! You've successfully authenticated, but GitHub does not provide shell access.