title: Linux禁止某个用户通过SSH登录
date: 2024-08-08 23:20:03.033
updated: 2024-08-08 23:20:03.033
url: https://liumou.site/doc/712
categories:

  • Linux
    tags:
  • Linux

配置

在配置文件

vim /etc/ssh/sshd_config

添加以下内容

DenyUsers <用户名>

例如

DenyUsers l

然后重启

systemctl daemon-reload&&systemctl restart ssh

效果

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则无法登录