环境:Mac
我的ssh_keys:~/.ssh/id_rsa.pub
1. 生成ssh keys
打开命令行
ssh-keygen -t rsa -C 'XXX@XX.com'
-C的参数是邮箱地址,然后回车
一通操作下来我的ssh_keys是~/.ssh/id_rsa.pub
cd ~/.ssh
cat id_rsa.pub
2. 修改ssh_config
打开命令行修改config设置
cd /etc/ssh
sudo vim ssh_config # 这个需要有sudo权限
在ssh_config文件的Host块中新增两行
IdentityFile ~/.ssh/your_private_key_filename #这里填自己的ssh_keys文件信息
UseKeychain yes
最后填完的样子我的是这样:
Host *
SendEnv LANG LC_*
IdentityFile ~/.ssh/id_rsa
UseKeychain yes
需要说明的是不能写成IdentityFile ~/.ssh/id_rsa.pub
,.pub
是不能加的,会提示
Permissions 0644 for '/Users/XXX/.ssh/id_rsa.pub' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/Users/XXX/.ssh/id_rsa.pub": bad permissions
Permission denied, please try again.
网友评论