linux关闭在线登录用户和禁止root/IP直接ssh登录linux

在使用电脑的时候,发现自己的电脑上有其他的用户登陆。如果其他用户用的是自己的名字,那么就能通过who去查询出来,但是如果登陆的都是root用户,那么肯定不知道是谁,所以需要我们清除他们;另外呢,如果登陆的用户突然断掉,那么肯定会有过期的登陆信息需要清除

1,查明登陆端口;
# who
root pts/1 Apr 8 00:06 (172.29.0.29)
root pts/2 Apr 8 04:15 (172.29.0.21)

2,通知该用户将要关闭他:
# echo "I will close your connection" > /dev/pts/2
这样他的终端将显示该信息。

3,关闭用户连接
# fuser -k /dev/pts/2

 

 

/etc/ssh/sshd_config加上
PermitRootLogin no

service sshd restart    OR /etc/init.d/sshd restart

 

允许特定的帐户和ip登录

AllowUsers jinlai@192.168.0.11

或者

AllowUsers jinlai

/etc/init.d/sshd restart

 

vi /etc/hosts.allow

sshd:192.168.0.100:allow       //允许IP 192.168.0.100 登录
sshd:192.168.0.:allow          //允许IP 192.168.0.   网段登录
sshd:all:deny                   //禁止其他的所有IP登录
或者
sshd:223.227.223.*:allow              //允许IP 223.227.223.* 网段登录
sshd:192.168.0.*:allow             //允许IP 192.168.0.*   网段登录
sshd:all:deny                                //禁止其他的所有IP登录

freeBSD限制特定ip的ssh登陆:
1.
#ee /etc/hosts.allow
在ALL : ALL : allow的前面加上
sshd : 192.168.0.100 : allow
sshd : 223.227.223.* : allow
sshd : ALL : deny



2.
修改/etc/ssh/sshd_config
加入
Allowusersadmin@172.16.2.188
意思为
只允许admin从172.16.2.188登陆

posted @ 2012-07-05 16:21  曾先森在努力  阅读(1583)  评论(0编辑  收藏  举报