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

2020-02-23  本文已影响0人  Hemingway_AT

之前单独为 gitee 添加 SSH 公钥

关联文件 | 码云 gitee

【增】为 github 添加 SSH 公钥

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

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

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

mv id_rsa id_rsa_gitee
mv id_rsa.pub id_rsa_gitee.pub
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f "id_rsa_github"
关联文件 | GitHub

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

# 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
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 :)

参考

上一篇下一篇

猜你喜欢

热点阅读