centos7设置ssh安全策略

作者: 带鱼兄 2017-01-31 11:11:23

准备环境:


1.两台虚拟机,系统是centos7,IP1:192.168.1.103,IP2:192.168.1.106


2.IP1的SSH的默认端口是22,这里修改为2222


3.只允许IP2通过SSH登录IP1


4.不允许root账户直接ssh登录


 


第一步:检查防火墙设置


a) 检查防火墙是否开启


systemctl status firewalld.service




b) 如果防火墙开启,检查端口是否放行


firewall-cmd --zone=public --list-port


c) 如果端口不放行,则放行此端口


firewall-cmd --zone=public --add-port=2222/tcp --permanent


d) 重载防火墙设置


firewall-cmd --reload


 


第二步:检查SELinux(访问控制系统)


a) 检查SELinux是否开启,enabled表示开启


sestatus -v | grep "SELinux status"


b) 通过semanage(默认系统不自带,需要安装)设置SELinux,允许新的SSH端口


yum install policycoreutils-python  


semanage port -a -t ssh_port_t -p tcp 2222  


semanage port -l | grep ssh  


成功后可以看到2222端口的输出信息


 


第三步:配置SSH端口


vim /etc/ssh/sshd_config


a) 修改端口,默认是22


Port 2222


b) 禁止root账户通过SSH直接登录,默认是yes


PermitRootLogin no


 


第四步:限制SSH登录的IP


a) 设置禁止所有ip连接服务器的SSH


vim /etc/hosts.deny


sshd:all:deny


b) 设置允许指定ip连接服务器的SSH


vim /etc/hosts.allow


sshd:192.168.1.106:allow


 


第四步:重启SSH服务,并通过登录进行验证


systemctl restart sshd.service


systemctl status sshd.service


 


本文永久更新地址:http://www.linuxdiyf.com/linux/28076.html

相关资讯