| 为 gitee/github 生成/添加 SSH 公钥

之前单独为 gitee 添加 SSH 公钥

关联文件 | 码云 gitee

【增】为 github 添加 SSH 公钥

切到 ~/.ssh目录下,欲执行以下官方演示命令,将在 .ssh 目录下默认生成 id_rsa文件。

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

可以预见会与 gitee 那一套有冲突。

  • 因此,对之前 gitee 生成公钥时的关联文件进行重命名
mv id_rsa id_rsa_gitee
mv id_rsa.pub id_rsa_gitee.pub
  • 为 github 生成 SSH 公钥并指定命名
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f "id_rsa_github"
关联文件 | GitHub
  • 将账户添加密钥,内容为id_rsa_github.pub中的字符

拷贝到剪切板的命令如下:

# Mac
$ pbcopy < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
# Windows
$ clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
# Linux
$ sudo apt-get install xclip
# Downloads and installs xclip. If you don't have `apt-get`, you might need to use another installer (like `yum`)

$ xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
  • 进行连接测试,结果发生了意外:Permission denied(出现原因:多个git环境下,使用了自定义的秘钥名称)
ssh -T git@github.com
failure :(

解决方案:新建 config 文件,进行配置,如下

# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gitee

# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github

再次进行连接测试,就好了!

success :)

参考

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容