ssh key 免密登录
- 生成公钥与密钥
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