Gitee(码云)、Github同时配置ssh key

  1. 进入ssh目录
cd ~/.ssh
  1. 使用命令分别创建两个平台的公钥
ssh-keygen -t rsa -C "[email protected]" -f "id_rsa_gitee"
ssh-keygen -t rsa -C "[email protected]" -f "id_rsa_github"

完成后,目录内容如下:

-rw-------   1 rpp  staff   2.5K  6 18  2020 id_rsa
-rw-r--r--   1 rpp  staff   570B  6 18  2020 id_rsa.pub
-rw-------   1 rpp  staff   2.5K  6 24  2020 id_rsa_gitee
-rw-r--r--   1 rpp  staff   570B  6 24  2020 id_rsa_gitee.pub
-rw-------   1 rpp  staff   2.5K  6 24  2020 id_rsa_github
-rw-r--r--   1 rpp  staff   568B  6 24  2020 id_rsa_github.pub
-rw-r--r--   1 rpp  staff   3.7K  6  6 11:12 known_hosts
  1. 将产生的公钥xxx.pub内容分别配置到Github和Gitee
  2. 在.ssh目录下创建config文件,解决SSH冲突,添加如下内容:
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github

# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gitee
  1. 测试,命令如下:
ssh -T [email protected]
或者
ssh -T [email protected]

成功后提示

Hi xxxx! You've successfully authenticated, but GITEE.COM does not provide shell access.
  1. 遇到问题,在测试环节,有时会出现如下错误:
# Linux
Bad owner or permissions on /home/lambda/.ssh/config
# Windows
Bad owner or permissions on C:\\Users\\Ran\\.ssh\\config

解决办法如下

  • linux
sudo chmod 600 ~/.ssh/config
  • windows
  1. 查看PATH环境中是否存在C:\Windows\System32\OpenSSH\ssh.exe
  2. 将C:\Windows\System32\OpenSSH\ssh.exe改成C:\Program Files\Git\usr\bin\ssh.exe

你可能感兴趣的:(Liunx,ssh,github,linux)