1,修改ssh端口
2,禁止root通过ssh远程登录
3,限制用户的SSH访问
4,配置空闲超时退出时间间隔
5,限制只有某一个IP才能远程登录服务器

#修改ssh端口

[root@localhost ~]# vi /etc/ssh/sshd_config
在端口#Port 22下面增加Port 2222
[root@localhost ~]# vi /etc/ssh/ssh_config
在端口#Port 22下面增加Port 2222

[root@localhost ~]# service sshd restart

#禁止root通过ssh远程登录

[root@localhost ~]# vi /etc/ssh/sshd_config
#找到PermitRootLogin,将后面的yes改为no,把前面的注释#取消,这样root就不能远程登录了
#可以用普通账号登录进去,要用到root的时候使用命令su root 切换到root账户

#限制用户的SSH访问

假设我们只要root,userA和userB用户能通过SSH使用系统,向sshd_config配置文件中添加
[root@localhost ~]# vi /etc/ssh/sshd_config
AllowUsers root userA  userB

#配置空闲超时退出时间间隔

用户可以通过ssh登录到服务器,你可以设置一个空闲超时时间间隔。
打开sshd_config配置文件,设置为如下。
[root@localhost ~]# vi /etc/ssh/sshd_config
ClientAliveInterval 600
ClientAliveCountMax 0

上面的例子设置的空闲超时时间间隔是600秒,即10分钟,
过了这个时间后,空闲用户将被自动踢出出去(可以理解为退出登录/注销)。

#限制只有某一个IP才能远程登录服务器

[root@localhost ~]# vi /etc/hosts.deny     
#在其中加入sshd:ALL
[root@localhost ~]# vi /etc/hosts.allow    
#在其中进行如下设置:
sshd:192.168.1.1    
#(只允许192.168.1.1这个IP远程登录服务器)