1. 程式人生 > >centos7下ssh登陸加固方案

centos7下ssh登陸加固方案

     因為網路安全問題,需要對centos7下的ssh服務進行安全加固,下面會給出詳細操作步驟及思路。

     由於centos7系統預設安裝啟用了系統高階防火牆,ssh服務預設開啟是22埠,如果直接在ssh的配置檔案中對監聽埠進行更改,重啟sshd服務後不會成功,提示無法繫結埠,所以要修改ssh的埠,需要首先修改系統防火牆配置

    一、ssh登陸埠修改

        1、防火牆上新增ssh監聽埠

              firewall-cmd --permanent --zone=public --add-port=3333/tcp  #對public區域新增一個埠3333協議為tcp

              firewall-cmd --reload   #新增完成後需要過載配置檔案生效配置

       2、檢視新增情況

              firewall-cmd --zone=public --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources: 
  services: ssh
  ports: 3333tcp
  protocols: 
  masquerade: no
  forward-ports: 
  sourceports: 
  icmp-blocks: 
  rich rules: 

     3、修改ssh配置檔案中的監聽埠為3333

          vim /etc/ssh/sshd_config

          找到port 22,替換為Port 3333,並且把前面的#號去掉

          完成修改後儲存退出。

         service sshd restart   #重啟服務使監聽埠更換為3333

     4、這時通過nmap對主機進行掃描可以發現ssh 22已經關閉

        PORT   STATE  SERVICE VERSION
             22/tcp closed ssh    

      5、對22埠進行流量處理,使nmap無法探測出任何資訊

  firewall-cmd --permanent --zone=public --remove-port=22/tcp     #防火牆刪除原來的22埠

      firewall-cmd --permanen --zone=public --add-forward-port=port=22:proto=tcp:toport=22:toaddr=127.0.0.1  #將 22 埠的訪問流量轉向訪問者本地

   firewall-cmd --reload   

       6、此時再次掃描,無任何埠資訊顯示,埠已經完美更改

   二、網路層IP地址限制

      埠隱藏無法完全保障安全,最好可以基於服務+IP地址的限制,通過對/etc/hosts.allow檔案進行編輯,規則是隻允許白名單內的IP地址可以訪問本機的ssh,其它IP地址一律不允許;

     [[email protected] ~]# vim  /etc/hosts.allow 
#
# hosts.allow   This file contains access rules which are used to
#               allow or deny connections to network services that
#               either use the tcp_wrappers library or that have been
#               started through a tcp_wrappers-enabled xinetd.
#
#               See 'man 5 hosts_options' and 'man 5 hosts_access'
#               for information on rule syntax.
#               See 'man tcpd' for information on tcp_wrappers
#
sshd:192.168.1.11:allow    #允許192.168.1.11通過訪問本機的ssh服務
sshd:192.168.1.12:allow   #允許192.168.1.12通過訪問本機的ssh服務
sshd:all:deny                       #預設全部拒絕訪問

   三、應用層對賬號+IP進行限制

    通過對/etc/ssh/sshd_config檔案進行配置,可以實現比hosts.allow更加豐富的限制,hosts.allow是基於網路層的限制,這裡可以實現業務層限制,限制規則是IP+賬號,限制指定登陸IP只能通過指定賬號登陸。

Allowusers [email protected]   #192.168.1.11可以使用root登陸
Allowusers [email protected]   #192.168.1.12只能使用test賬號登陸

  四、加固總結

   加固思路,首先要確保資訊洩露的越少越好,不要洩露服務型別,系統型別,通過第一步修改埠加引流操作,使得外部探測失去準星,然後還要在作業系統中基於網路層對可以訪問的IP地址列白名單,最後是對白名單使用者進行賬號許可權登陸指定,通過三步操作,完成對centos7作業系統ssh業務的加固。

   加固效果要隨時通過nmap進行掃描確認,下面是加固以後的效果。所有操作涉及ssh配置檔案/etc/ssh/sshd_config,作業系統網路層ip限制檔案/etc/hosts.allow,測試加固效果的軟體是nmap。

nmap -sS -v -A 192.168.1.1


Starting Nmap 6.49BETA5 ( https://nmap.org ) at 2017-05-11 21:58 CST
NSE: Loaded 122 scripts for scanning.
NSE: Script Pre-scanning.
Initiating NSE at 21:58
Completed NSE at 21:58, 0.00s elapsed
Initiating NSE at 21:58
Completed NSE at 21:58, 0.00s elapsed
Initiating Ping Scan at 21:58
Scanning 192.168.1.1 [4 ports]
Completed Ping Scan at 21:58, 0.07s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 21:58
Completed Parallel DNS resolution of 1 host. at 21:58, 0.01s elapsed
Initiating SYN Stealth Scan at 21:58
Scanning 192.168.1.1 [1000 ports]
Completed SYN Stealth Scan at 21:58, 14.38s elapsed (1000 total ports)
Initiating Service scan at 21:58
Initiating OS detection (try #1) against 192.168.1.1
Initiating Traceroute at 21:58
Completed Traceroute at 21:58, 0.01s elapsed
Initiating Parallel DNS resolution of 1 host. at 21:58
Completed Parallel DNS resolution of 1 host. at 21:58, 0.01s elapsed
NSE: Script scanning 192.168.1.1
Initiating NSE at 21:58
Completed NSE at 21:58, 0.01s elapsed
Initiating NSE at 21:58
Completed NSE at 21:58, 0.00s elapsed
Nmap scan report for 192.168.1.1
Host is up (0.00064s latency).
All 1000 scanned ports on 192.168.1.1 are filtered
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Device type: WAP|firewall
Running: Asus embedded, Palo Alto embedded
OS CPE: cpe:/h:asus:rt-53n cpe:/h:paloalto:pa-500
OS details: Asus RT-53N WAP, Palo Alto PA-500 firewall  #如果不做加固,會直接識別為linux具體版本和服務,暴露非常多的資訊

Network Distance: 1 hop


TRACEROUTE (using port 80/tcp)
HOP RTT     ADDRESS
1   0.86 ms 192.168.1.1


NSE: Script Post-scanning.
Initiating NSE at 21:58
Completed NSE at 21:58, 0.00s elapsed
Initiating NSE at 21:58
Completed NSE at 21:58, 0.00s elapsed
Read data files from: /usr/bin/../share/nmap
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 17.11 seconds
           Raw packets sent: 2021 (90.330KB) | Rcvd: 35 (2.570KB)

--------------------下面顯示加固前的nmap掃描結果

22/tcp open  ssh     OpenSSH 6.6.1 (protocol 2.0)               #直接顯示埠服務及具體openssh的版本資訊
| ssh-hostkey: 
|   2048 79:38:a3:18:ce:9d:a7:16:5c:bd:61:12:95:30:aa:6c (RSA)
|_  256 2f:a7:3e:d8:fd:b1:2b:9a:af:03:38:44:73:f2:55:ad (ECDSA)
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Device type: general purpose|storage-misc|WAP|load balancer|firewall
Running (JUST GUESSING): Linux 2.6.X (94%), Netgear Linux 2.6.X (93%), Linksys embedded (91%), Ubiquiti Linux 2.6.X (90%), F5 Networks embedded (87%), Palo Alto embedded (87%), F5 Networks TMOS 11.1.X (85%)
OS CPE: cpe:/o:linux:linux_kernel:2.6 cpe:/o:netgear:linux_kernel:2.6 cpe:/h:linksys:befw11s4 cpe:/o:ubiquiti:linux_kernel:2.6 cpe:/h:paloalto:pa-500 cpe:/o:f5:tmos:11.1
Aggressive OS guesses: Linux 2.6.32 (94%), Netgear ReadyNAS 3200 NAS device (Linux 2.6) (93%), Linksys BEFW11S4 WAP (91%), Linux 2.6.11 - 2.6.18 (90%), Ubiquiti WAP (Linux 2.6.32) (90%), F5 BIG-IP load balancer (87%), Palo Alto PA-500 firewall (87%), F5 3600 LTM load balancer (85%), Netgear WNDAP660 WAP (Linux 2.6.36) (85%)
No exact OS matches for host (test conditions non-ideal).
Uptime guess: 1.245 days (since Thu May 11 08:42:05 2017)

相關推薦

centos7ssh登陸加固方案

     因為網路安全問題,需要對centos7下的ssh服務進行安全加固,下面會給出詳細操作步驟及思路。      由於centos7系統預設安裝啟用了系統高階防火牆,ssh服務預設開啟是22埠,如果直接在ssh的配置檔案中對監聽埠進行更改,重啟sshd服務後不會成功,提

CentOS7SSH登陸使用Google Authenticator兩步驗證

實驗環境:CentOS-7-x86_64-Minimal-1804 必須要關閉SELINUX 臨時關閉SELinux,重啟後失效: setenforce 0 永久關閉,需要reboot重啟後生效: vim /etc/selinux/config S

linux通過ssh登陸失敗解決方案

在一臺linux機器上ssh遠端另外一臺linux伺服器時候出現: [[email protected] .ssh]# ssh 192.0.50.80 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

SSH登陸阿裏雲服務器出現Permission denied (publickey)錯誤解決方案

ckey 是個 鑰匙串 col code gen fff font 重啟 操作環境: 操作系統:Mac10.11.5 阿裏雲服務器:Ubuntu16.04 遠程連接:SSH 註:首先我們已假設你已經自己生成了SSH秘鑰,並已經配置到阿裏雲、綁定了自己的雲服務器。 但是

MacOS免密碼ssh登陸

通過 頻繁 span 免密 使用 -c 基於 依賴 oot 由於配置過程中需要頻繁的進行ssh連接到開發服務器執行命令以及通過scp命令向服務器拷貝文件等依賴ssh連接的操作。所以,配置本地環境跟服務器之間的ssh免密碼連接可以有效的提升工作效率。 由於我本機已經

CentOS7Tomcat啟動慢的原因及解決方案

按鍵 source 命令 mon 進程 tomcat apps 守護進程 中斷 現象   在一次CentOS 7系統中安裝Tomcat,啟動過程很慢,需要幾分鐘,經過查看日誌,發現耗時在這裏:是session引起的隨機數問題導致的。Tocmat的Session ID是通過S

linuxssh連接慢的原因調查及解決方案

acc 設置 發現 lin opened 左右 config 連接 war 項目中的一臺阿裏雲,最近一段時間出現ssh的時候,連接非常慢,大概輸入密碼後要10-20秒左右才能連上,以下記錄調查過程及解決辦法 通過網上的一些查詢,發現大都是因為設置dns,hosts或者通過關

linuxssh key秘鑰登陸遠程服務器設置

linu ash spa cati open cat server ssh env 本地的用戶名需要和ssh服務器的用戶名一致 1、在Server服務器上加載私鑰文件ssh-add wang_rsa 2、如果系統提示:could not open a connection

windows 系統利用SecureCRT、xshell 生成ssh登陸linux的公鑰

windows 公鑰生成方法一 使用SecureCRT 工具 1、打開我們的SecureCRT客戶端,點擊tool-->create public key.. 2、密鑰類型我們選擇非對稱類型的RSA,按照提示下一步。 3、通行短語設置,在連接上服務器的時候需要輸入,設置後是可以通過securec

centos7升級SSH

HA c++編譯器 tro 分享 keyword 系統安全 org blank 哪裏 Linux 發行版中集成的 SSH 軟件版本都比較老,存在著一些漏洞和安全隱患,需要升級 SSH 服務軟件修補漏洞提升系統安全。 SSH:SSH 有許多標準,通常 Linux 中 (

Centos7實現ssh免密登陸

manage oca sent centos7 main with false SQ present 1通過ssh-copy-id的方式 1 [root@localhost ~]# ssh-copy-id -i root@worker1 2 /usr/bin/ssh-

Centos7 配置ssh免密登陸以及遇到的問題

同樣以Ubuntu為例,假設使用者名稱為u: 1)確認已經連線上網際網路,然後輸入命令: sudo apt-get install ssh 2)配置為可以免密碼登入本機。首先檢視在u使用者下是否存在.ssh資料夾(注意ssh前面有“.”,這是一個隱藏資料夾),輸入命令: ls –a

centos7 系統安全加固方案

防止 默認 class one crack 遠程登錄 數字 mef alt 一.密碼長度與有效期 默認配置: [root@i-1y3we23j ~]# cat /etc/login.defs |grep PASS_ |grep -v ‘#‘ PASS_MAX_DAYS

centos7 python3 和python2 同時存在但是無法使用pip3 的解決方案

        歷經千辛萬苦終於把python3 裝上了,想要pip install一下numpy,發現numpy已存在於python2.7的目錄下,於是納悶為什麼這裡執行的pip是Python2.7的,因為現在預設的Python是3.7的。        於是就開始百度,找

CentOS7安裝、簡單配置和SSH遠端連結mysql

1. 下載並安裝Mysql開源社群版 在Linux環境下,有yum、rpm等軟體安裝方式。 yum(全稱為 Yellow dog Updater, Modified)是一個在Fedora和RedHat以及SUSE中的Shell前端軟體包管理器。 基於

Centos6.5SSH免密碼登陸配置

配置SSH無密碼登陸 本教程配置說明 目的:實現主機名分別為 name 和 data2 的SSH免密碼登陸 兩臺主機均在hadoop使用者下進行操作 兩臺主機已實現基本網路配置 特別強調:免密碼ssh登陸每個個機子的/etc/hosts 的檔案內必

hadoop學習筆記(五)——全分佈模式SSH免密碼登陸的實現

1)  設定3臺機器的網路配置,並統一使用者名稱,root除外 master:192.168.2.10 slave1:192.168.2.11 slave2:192.168.2.12 2)  SSH免

CentOS7使用ssh不能登錄,報錯:Read from socket failed: Connection reset by peer

read from socket failed: connection reset by peer使用xshell登錄CentOS7,不能登錄,使用另外一臺Linux主機,telent 22端口是同的,ssh連接報以下錯誤:Read from socket failed: Connection reset b

centos7yum快速安裝 mariadb(mysql)

版本 repos 測試 tar b-s 新版 roo system -s 從最新版本的centos系統開始,默認的是 Mariadb而不是mysql! 使用系統自帶的repos安裝很簡單: yum install mariadb mariadb-server systemc

Centos7安裝 JDK1.8

class bce hostname etc 下載 nod tar.gz 執行 profile   最近看了一篇技術文章, 用 nginx+tomcat+redis+centos 實現 session 共享等功能,覺得很有用,就跟著文章在 Centos7 的環境下搭建了幾個