Skip to content

配置

在配置文件

bash
vim /etc/ssh/sshd_config

添加以下内容

bash
DenyUsers <用户>

例如

bash
DenyUsers l

然后重启

bash
systemctl daemon-reload&&systemctl restart ssh

效果

bash
liu@SSH:/$ cat /etc/ssh/sshd_config | grep -i deny
DenyUsers l
liu@SSH:/$ 
exit
$ ^[[A^C
$ 
Connection to 172.20.19.2 closed.
root@tb4:~# ssh liu@172.20.19.2
liu@172.20.19.2's password: 
Last login: Thu Aug  8 15:13:28 2024 from 172.20.19.100
$ 
Connection to 172.20.19.2 closed.
root@tb4:~# ssh l@172.20.19.2
l@172.20.19.2's password: 
Permission denied, please try again.
l@172.20.19.2's password: 
Permission denied, please try again.
l@172.20.19.2's password:

可以看到,用户名liu是正常登录的,用户名l则无法登录

Last updated: