RedHat SSH 安全設定

  • Post by
  • May 09, 2023
post-thumb

在 RedHat 或類似的 Linux 系統上,配置 SSH 伺服器 (sshd) 的安全設定是一個重要的管理任務。適當的設定可以幫助防止未經授權的訪問和潛在的安全威脅。

檢查當前 SSH 加密模式

首先檢查當前配置的 SSH 加密模式,確保使用的是安全的加密套件。

sudo sshd -T | grep "\(ciphers\|macs\)"

確保使用如下的安全加密模式:

更新 SSH 配置

如果當前配置不符合安全標準,可以修改 /etc/ssh/sshd_config 文件以更新設定。

步驟:

  1. 使用文本編輯器開啟 SSHD 配置文件:

    sudo vi /etc/ssh/sshd_config
    
  2. 確保添加或更新以下行以反映安全的加密和 MACs 設定:

    Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com
    MACs hmac-sha2-512,hmac-sha2-256
    
  3. 保存並退出編輯器。

  4. 為了使配置更改生效,重新啟動 SSH 服務:

    sudo systemctl restart sshd
    

確保 SSH 安全性的其他提示

  • 禁止 root 登錄:PermitRootLogin no
  • 禁用密碼認證:PasswordAuthentication no
  • 啟用公鑰認證:PubkeyAuthentication yes
  • 設置合理的登錄嘗試次數限制:MaxAuthTries 3
  • 使用非標準端口(非預設的 22 端口):Port 2222
  • 監控並記錄所有 SSH 活動

在配置 SSH 伺服器時,始終要注意平衡安全性和可用性。適當的配置和定期審計可以顯著提高系統的安全性。

完整/etc/ssh/sshd_config範例參考


Port 22
#AddressFamily any

ListenAddress 0.0.0.0
ListenAddress ::

Protocol 2

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

#RekeyLimit default none

Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com

KexAlgorithms ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256

MACs hmac-sha2-512,hmac-sha2-256

#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

#LoginGraceTime 2m
PermitRootLogin prohibit-password
#StrictModes yes

#MaxAuthTries 6

#MaxSessions 10

#PubkeyAuthentication yes

#AuthorizedKeysFile	.ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

#HostbasedAuthentication no
#IgnoreUserKnownHosts no
#IgnoreRhosts yes

PasswordAuthentication yes

PermitEmptyPasswords  no

KbdInteractiveAuthentication no

#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed

#ClientAliveInterval 0
#ClientAliveCountMax 3
UseDNS no
#PidFile /run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

#Banner none

AcceptEnv LANG LC_*

Subsystem sftp /usr/libexec/openssh/sftp-server

#Match User anoncvs
#	X11Forwarding no
#	AllowTcpForwarding no
#	PermitTTY no
#	ForceCommand cvs server

相關CVE弱點

  • CVE-2008-5161 是指與 Red Hat Enterprise Linux 中h的 OpenSSL 套件相關的一個安全問題。該問題源於 OpenSSL 中的一個漏洞,該漏洞在處理某些類型的私鑰時可能會導致 OpenSSL 當機。
  • CVE-2016-2183 是指與 Red Hat Enterprise Linux 中的 OpenSSL 套件相關的一個安全問題。該問題源於 OpenSSL 中對於 BLOCK-CIPHERS(如3DES)的處理方式,這可能會使攻擊者進行甜蜜32攻擊(Sweet32 attack)。
  • CVE-2013-2566 是指與 Red Hat Enterprise Linux 中的 OpenSSL 套件相關的一個安全問題。該問題源於 OpenSSL 中對於 BLOCK-CIPHERS(如 RC4)的處理方式,這可能會使攻擊者進行選擇明文攻擊。
  • CVE-2015-2808 是指與 Red Hat Enterprise Linux 中的 OpenSSL 套件相關的一個安全問題。該問題源於 OpenSSL 中對於 BLOCK-CIPHERS(如 RC4)的處理方式,這可能會使攻擊者進行巴拉迪和波格丹諾夫(Bar-Mitzvah)攻擊。
LATEST POST
TAG