配置SSH证书登录验证

1)先添加一个维护账号:msa 
2)然后su - msa
3)ssh-keygen -t rsa 指定密钥路径和输入口令之后,即在/home/msa/.ssh/中生成公钥和私钥:id_rsa id_rsa.pub
4)cat id_rsa.pub >> authorized_keys 至于为什么要生成这个文件,因为sshd_config里面写的就是这个。 然后chmod 400 authorized_keys,稍微保护一下。 
5)用psftp把把id_rsa拉回本地,然后把服务器上的id_rsa和id_rsa.pub干掉 

6)配置/etc/ssh/sshd_config 

   Protocol 2 
   ServerKeyBits 1024 
   PermitRootLogin no #禁止root登录而已,与本文无关,加上安全些 


 #以下三行没什么要改的,把默认的#注释去掉就行了 


  RSAAuthentication yes 

  PubkeyAuthentication yes 

  AuthorizedKeysFile .ssh/authorized_keys 

  PasswordAuthentication no

  PermitEmptyPasswords no 


7)重启sshd /sbin/service sshd restart
8)转换证书格式,迁就一下putty 运行puttygen,转换id_rsa为putty的ppk证书文件 
9)配置putty登录 在connection--SSH--Auth中,点击Browse,选择刚刚转换好的证书。 然后在connection-Data填写一下auto login username,例如我的是msa 在session中填写服务器的IP地址,高兴的话可以save一下
10)解决一点小麻烦 做到这一步的时候,很可能会空欢喜一场,此时就兴冲冲的登录,没准登不进去: No supported authentication methods available 这时可以修改一下sshd_config,把 PasswordAuthentication no 临时改为: PasswordAuthentication yes 并重启sshd 这样可以登录成功,退出登录后,再重新把PasswordAuthentication的值改为no,重启sshd。 以后登录就会正常的询问你密钥文件的密码了,答对了就能高高兴兴的登进去。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值