linux禁止用户使用ssh登录服务器
原创小于 1 分钟linuxlinuxsshsshd_config服务器安全
提示
是的,我们会有很多种方法去实现它。现在使用比较简单的两种方法
方案一
编辑/etc/ssh/sshd_config配置文件,
# 禁用单个用户
echo "DenyUsers username" >> /etc/ssh/sshd_config
# 禁用某个组
echo "DenyGroups group" >> /etc/ssh/sshd_config
# 重启ssh服务
systemctl restart sshd
方案二
vim /etc/passwd
找到你需要修改的用户名的那一行
将登录方式修改为/user/sbin/nologin,例:
mantang:x:1001:1001::/data/ftp:/user/sbin/nologin
禁止Root用户ssh登录
禁止之前,请确保系统至少拥有一个普通账户并能够登录
编辑配置文件
vim /etc/ssh/sshd_config
将PermitRootLogin 修改为no, (默认注释,并为 yes)
PermitRootLogin no
重启ssh服务
systemctl restart sshd