SSH配置文件


一 ssh配置文件路徑

1.1 ssh客戶端配置文件:

路徑:/etc/ssh/ssh_config

1.2 ssh服務端配置文件:

路徑:/etc/ssh/sshd_config

二 服務器端常用配置選項

2.1 常見配置項

 1 Port 22 #端口
  2 
  3 ListenAddress #監聽的IP
  4 
  5 Protocol 2 #SSH版本選擇
  6 
  7 HostKey /etc/ssh/ssh_host_rsa__key #私鑰保存位置
  8 
  9 ServerKeyBits #1024
 10 
 11 ServerFacility AUTH #日志記錄ssh登陸情況
 12 
 13 #KeyRegenerationInterval 1h #重新生成服務器密鑰的周期
 14 
 15 #ServerKeyBits 1024 #服務器密鑰的長度
 16 
 17 LogLevel INFO #記錄sshd日志消息的級別
 18 
 19 #PermitRootLogin yes #是否允許root遠程ssh登錄
 20 
 21 #RSAAuthentication yes #設置是否開啟ras密鑰登錄方式
 22 
 23 #PubkeyAuthentication yes #設置是否開啟公鑰驗登錄方式
 24 
 25 #AuthorizedKeysFile .ssh/authorized_keys #設置公鑰驗證文件的路徑
 26 
 27 #PermitEmptyPasswords no #設置是否允許空密碼的賬號登錄
 28 
 29 X11Forwarding yes #設置是否允許X11轉發
 30 
 31 GSSAPIAuthentication yes #GSSAPI認證開啟

2.3 默認端口修改

注意:ssh默認端口號,建議修改為其他非常用端口。

 1 #Port 22                            #這行加#號注釋掉
  2 Port 2222                              #下面添加這一行

2.4 監聽IP地址

 1 ListenAddress

監聽的IP,允許某些特定的IP才可以ssh登陸進來。

2.5 采用SSH協議版本

1 Protocol 2

默認的ssh版本,建議采用第二代版本。

2.6 私鑰配置

1 HostKey /etc/ssh/ssh_host_rsa__key
  2 # HostKeys for protocol version 2
  3 HostKey /etc/ssh/ssh_host_rsa_key
  4 #HostKey /etc/ssh/ssh_host_dsa_key

版本v2的私鑰保存路徑。

2.7 加密位

 1 ServerKeyBits 1024

鑰匙串的加密位數,默認采用1024位加密。

2.8 日志等級

1 ServerFacility AUTH & LogLevel INFO

需要記錄日志,並設定日志等級為INFO,建議不用修改。

2.9 GGSSAP認證

 1 GGSSAPIAuthentication yes

GGSSAP認證默認已開啟,經過dns進行認證,嘗試將主機IP和域名進行解析。若管理主機無對外域名,建議在管理主機上在客戶端的配置文件將此認證關閉。

三 服務器端安全配置選項

 1 PermitRootLogin yes                #允許root的ssh登陸
  2 PubkeyAuthentication yes            #是否使用公鑰驗證
  3 AuthorizeKeysFile .ssh/authorized_keys        #公鑰的保存位置
  4 PasswordAuthentication yes            #允許使用密碼驗證登陸
  5 PermitEmptyPasswords no                #不允許空密碼登陸

注意:如果開啟公鑰驗證,可以關閉允許root登陸、關閉允許使用密碼驗證登陸,此時將采用公鑰驗證登陸,無需輸入密碼。建議采用此更安全的方式,直接使用私鑰和公鑰匹配的公鑰驗證方式。

四 SSH其他管理

[root@imxhy]# yum -y install policycoreutils-python

[root@imxhy]# semanage port -a -t ssh_port_t -p tcp 2222

[root@imxhy]# semanage port -l | grep ssh #查看SELinux設置

[root@imxhy]# firewall-cmd --permanent --add-port=2222/tcp

[root@imxhy]# systemctl restart firewalld.service

[root@imxhy]# systemctl restart sshd.service

 


免責聲明!

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



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