多个 ssh key git免密登录配置

ssh key 免密登录

  1. 生成公钥与密钥
ssh-keygen -t rsa -C "[email protected]" -f ~/.ssh/ssh_name

2.将公钥复制保存在gitlab/github的ssh选项中

  • github Settings --> SSH and GPG keys --> New SSH key
  • gitlab Edit profile --> SSH keys --> Add key

3.如果是用默认的ssh-key 文件名,一般不需要其他设置,此时就已经可以正常免密使用git push 等命令了。

4.如果是自定义了ssh-key的文件名,此时还需要更改下ssh_config文件里的配置

  • Mac 系统在~/.ssh/config 或者 /etc/ssh/ssh_config配置所使用的公私钥名称
vim /etc/ssh/ssh_config

Host *
#   ForwardAgent no
    IdentityFile ~/.ssh/id_rsa
    IdentityFile ~/.ssh/ssh_name

  • Win 系统 在Git的安装目录比如c/Program Files/Git/etc/ssh/ssh_config配置所使用的公私钥名称

    修复方法同上

如果是配置比如云服务器的ssh免密登录步骤与上述类似

1.首先生成密钥对放在本机的.ssh目录,如果是自定义了ssh-key的文件名还需要在ssh_config里加上相应的配置
2.需要在远程服务器的/root目录下的.ssh里的authorized_keys文件里追加上公钥的内容。
这一步可以用命令ssh-copy-id -i ~/.ssh/公钥.pub remote-host完成。也可以手动复制。
3.如果还连不上可以尝试修改 authorized_keys文件的权限为-rw-r--r--
sudo chmod 644 xxx

猜你喜欢

转载自blog.csdn.net/mochenangel/article/details/124884296