转载地址:https://blog.csdn.net/linghe301/article/details/8211305
linux 禁止/允许root远程连接登录的方法
vi /etc/ssh/sshd_config
将PermitRootLogin的值改为yes
service sshd restart (/etc/init.d/ssh restart)
就能用root直接ssh登录
将PermitRootLogin 的值该为no
就不能用root 直接ssh登录
linux 禁止普通用户登录
root 账号下修改 /etc/ssh/sshd_config
增加行 DenyUsers user
service sshd restart (/etc/init.d/ssh restart)
在linux禁止root远程登录的情况下,恢复root远程登录
以普通用户远程登录,
切换账号为root 账号:su - 回车输入root密码
切换成功后,vi /etc/ssh/sshd_config
将PermitRootLogin 的值该为yes
service sshd restart (/etc/init.d/ssh restart)
git server搭建时禁止远程登录git账号
本地可通过su切换git账户
最简单的方法:删掉git账号的密码
sudo passwd -d git
远程登录需要密码,输入任何密码均验证不成功
linux 限制ssh方式的用户登录
vi /etc/ssh/sshd_config
修改或增加:AllowUsers ccc
service sshd restart (/etc/init.d/ssh restart)
这样只能ccc登录,其余用户禁止登录
启动或禁止用户IP登录
除了可以限制用户登录,还可以针对固定的IP禁止登录
vi /etc/hosts.allow 配置文件,设置允许登录的IP
sshd:192.168.220.164:allow
vi /etc/hosts.deny 配置文件,设置sshd:ALL
sshd:ALL
禁止所有IP,但是允许相关IP登录
linux 下root 和当前用户互相转换命令
1. 从普通用户转换为root用户命令
su –
然后输入root用户的密码
2. 从root用户转换为普通用户命令
su xxx(用户名)