1、服务器端开启密钥登录模式

/etc/ssh/sshd_config

  1. # 是否允许 root 远程登录
  2. PermitRootLogin yes
  3. # 密码登录是否打开
  4. PasswordAuthentication yes
  5. # 开启公钥认证
  6. RSAAuthentication yes # 这个参数可能没有 没关系
  7. PubkeyAuthentication yes
  8. # 存放登录用户公钥的文件位置
  9. # 位置就是登录用户名的家目录下的 .ssh
  10. # root 就是 /root/.ssh
  11. # foo 就是 /home/foo/.ssh
  12. AuthorizedKeysFile .ssh/authorized_keys


service sshd restart

2、用户端创建自己的秘钥对

  1. ssh-keygen -t rsa -C "your@email.com"
  2. cd ~/.ssh/
  3. # 查看公钥
  4. cat id_rsa.pub
  5. # 配置登录别名 省去输 ip 麻烦
  6. vi config
  7. Host examp # 登录的服务器别名 ssh examp 就可以了
  8. HostName 233.233.233.233 #要登录的服务器ip
  9. Port 22
  10. User root #登录名
  11. IdentityFile ~/.ssh/id_rsa #你的私钥路径
  12. ServerAliveInterval 30
  13. TCPKeepAlive yes

3、将你的公钥添加至服务器端的公钥凭证

echo 你的公钥内容 >> ~/.ssh/authorized_keys

4、用户端即可免密登录

ssh exmap

原文链接