centos7設置ssh安全策略


准備環境:

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端口

 

[plain]  view plain  copy
 
  1. yum install policycoreutils-python  
  2. semanage port -a -t ssh_port_t -p tcp 2222  
  3. 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://blog.csdn.net/daiyudong2020/article/details/54782758


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM