1.禁止使用密码登录
设定SSH服务不能使用密码登录:
1)进入服务器配置文件:
[root@server ~]# cd /etc/ssh/
[root@server ssh]# ls
moduli ssh_host_ecdsa_key ssh_host_ed25519_key.pub
ssh_config ssh_host_ecdsa_key.pub ssh_host_rsa_key
sshd_config ssh_host_ed25519_key ssh_host_rsa_key.pub
# ssh_config客户端配置文件 sshd_config服务器配置文件
2)修改其中的密码认证:
[root@server ssh]# vim sshd_config
# 通过关键字查找到密码修改位置
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes
3)将密码认证选项改为no就可以了:
PasswordAuthentication no
:wq
4)重启服务:
[root@server ssh]# systemctl restart sshd
5)使用密码登录ssh服务器:
[kiosk@foundation5 ~]$ ssh root@172.25.5.10 -X
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
- 这时就已经不能使用密码登录了。
6)使用密钥对登录:
[root@client1 ~]# ssh root@172.25.5.10 -X
Last login: Tue Aug 18 16:14:02 2020 from 172.25.5.2
[root@server ~]#
- 这时依然可以使用密钥对登录。
这种方式更加安全,没有密钥对的连用户密码都不要想使用。
2.禁止远程登录root用户
root是超级管理员用户,使用root远程登录,万一用户误操作,不可恢复的结果。
我们可以sodu给他权限,但不能直接使用root。
所以仅允许普通用户远程登录。
1)在服务器的配置文件中设定root不能登录
[root@server ~]# vim /etc/ssh/sshd_config
#LoginG