-
从主机 A 直接免密登录主机 B 的方法:
- 在主机 B
~/.ssh/目录下生成公钥id_rsa.pub和私钥id_rsa - 在
~/.ssh/执行命令cat id_rsa.pub >> authorized_keys将公钥信息追加到可登录列表 - 设置好合适的文件权限
chmod 600 authorized_keys - 拷贝 B 的
~/.ssh/id_rsa为 A 的~/.ssh/id_rsa_to_b - 设置文件权限
chmod 600 id_rsa_to_b - 配置 A 的
~/.ssh/config,增加两行Host xxx,IdentityFile ~/.ssh/id_rsa_to_b,将 B 的主机地址(域名或 IP 地址)与私钥绑定 - 在 A 执行登录命令
ssh user@xxx.xxx.xxx.xxx,就可以免密登录了
- 在主机 B
~/.ssh/config 配置文件说明
1 | |
常见问题
ssh -i authFile xx@xx.xx.xx.xx以认证文件访问时,可能遇到报错:It is required that your private key files are NOT accessible by others.只要执行chmod 600 authFile一下就可以了