ssh通过跳板机设置集群免密登录

1. 在本机生成RSA公钥私钥

 ssh-keygen -t rsa -f cc123 -C "cc123 key" #cc123指定产生的文件名, 默认id_rsa, -C 指定*.pub文件说明
一直回车,会在~/.ssh/目录下生成cc123、cc123.pub两个文件
 
2. 拷贝id_rsa.pub文件中的内容到跳板机和你需要登录的机器的~/.ssh/authorized_keys文件中
 
3. 在本机~/.ssh/config中增加内容(注释要删除):
Host jumpserver    //跳板机别名
  HostName jumpserver_ip  //跳板机地址
  User your_username  //用户名
  Port xxx  //跳板机ssh端口
Host hostname  //需要登录的服务器别名
  HostName x.x.x.x  //服务器地址
  User your_username  //服务器的用户名
  ProxyCommand ssh -i ~/.ssh/cc123 -q -W %h:%p jumpserver //跳板机PoryxCommand
 
在本机ssh hostname,即可登录。
4. 免密不生效
  • .ssh文件目录权限  要求 700
  • .ssh/authorized_keys 文件权限 600
  • 重启服务器 sshd   service sshd restart

5. Bad owner or permissions on /home/xxx/.ssh/config

  • chmod 600 config
posted @ 2021-09-17 14:43  春树&暮云  阅读(512)  评论(0编辑  收藏  举报