实现方式:修改服务端/etc/ssh/sshd_config配置文件
1、找到/etc/ssh/sshd_config
文件后修改其中的#PermitRootLogin yes
为PermitRootLogin no
2、重启sshd服务
[root@villainc ssh]# systemctl restart sshd
补充:
设置只公私钥对登陆后,使用口令登录将被禁止
1、若要设置只允许以公私钥对的方式登陆就需要设置为PermitRootLogin without-password
#这里模拟口令登录失败,需要先删掉服务端的ssh登录授权文件authorized_keys文件
rm -rf ~/.ssh/authorized_keys
#root用户再次使用口令登录将被拒绝
[root@hsc .ssh]# ssh root@192.164.124.3
root@192.164.124.3's password:
Permission denied, please try again.
root@192.164.124.3's password:
2、同样设置所有用户是否允许口令登录设置PasswordAuthentication
,设置后也需要重启sshd服务systemctl restart sshd