Ubuntu 18.04 配置 github ssh 连接
测试时间:2022年9月8日
测试系统:Ubuntu 18.04
1 本地检查
在生成 SSH 密钥之前,先检查本地是否存在现有的 SSH 密钥
ls -al ~/.ssh
检查目录列表查看是否已经有 SSH 公钥。默认情况下,GitHub 的一个支持的公钥文件名是
- id_rsa.pub
- id_ecdsa.pub
- id_ed25519.pub
如果本地已经有密钥,则上传现有密钥。
如果本地没有密钥,则生成新的 SSH 密钥。
2 密钥生成
生成新的 SSH 密钥并将其添加到 ssh-agent
生成新的 SSH 密钥
ssh-keygen -t ed25519 -C "your_email@example.com"
如果使用的系统不支持 Ed25519 算法,则使用
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
进一步提示 “Enter a file in which to save the key(输入要保存密钥的文件)” ,键入 Enter 按键以接受默认文件位置
进一步提示设置安全密码,此处推荐不进行设置,直接回车跳过即可完成 SSH 密钥的生成
3 密钥添加
为 GitHub 账户添加 SSH 密钥
复制本地密钥
cat ~/.ssh/id_ed25519.pub
进入 GitHub 页面,进入用户设置中的 SSH 和 GPG 密钥设置
新建 SSH 密钥,并将拷贝的密钥粘贴进去,点击 Add SSH Key
4 连接测试
测试 SSH 连接
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)?
证所看到消息中的指纹是否与 GitHub 的公钥指纹匹配。 如果是,则键入 yes
:
> Hi username! You've successfully authenticated, but GitHub does not
> provide shell access.