linux服务器设置只允许密钥登陆

首先需要修改一些配置文件

vim /etc/ssh/sshd_config

进入sshd_config文件后需要更改几个地方

 PubkeyAuthentication yes    #启用公告密钥配对认证方式 
 AuthorizedKeysFile  %h/.ssh/authorized_keys    #设定PublicKey文件路径
 RSAAuthentication yes  #允许RSA密钥
 PasswordAuthentication no #禁止密码验证登录,如果启用的话,RSA认证登录就没有意义了
 #禁用root账户登录,非必要,但为了安全性,请配置
 PermitRootLogin no

其实我在配置的时候发现其中有些找了很多遍都没有找到,然后我就直接手动照着输入一遍也是可以的。

然后保存配置,重新启动服务

service sshd restart
原文地址:https://www.cnblogs.com/xingyunfashi/p/9395571.html