sshd配置文件詳解


 

 

[root@test ~]# cat /etc/ssh/sshd_config
#       $OpenBSD: sshd_config,v 1.73 2005/12/06 22:38:28 reyk Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options change a
# default value.

 

#############1. 關於 SSH Server 的整體設定##############
#Port 22    
##port用來設置sshd監聽的端口,為了安全起見,建議更改默認的22端口為5位以上陌生端口
#Protocol 2,1
Protocol 2
##設置協議版本為SSH1或SSH2,SSH1存在漏洞與缺陷,選擇SSH2
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress用來設置sshd服務器綁定的IP地址
##監聽的主機適配卡,舉個例子來說,如果您有兩個 IP, 分別是 192.168.0.11192.168.2.20 ,那么只想要
###開放 192.168.0.11 時,就可以設置為:ListenAddress 192.168.0.11
####表示只監聽來自 192.168.0.11 這個 IP 的SSH聯機。如果不使用設定的話,則預設所有接口均接受 SSH

#############2. 說明主機的 Private Key 放置的檔案##########                 
#ListenAddress ::
##HostKey用來設置服務器秘鑰文件的路徑
# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
##設置SSH version 1 使用的私鑰

# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
##設置SSH version 2 使用的 RSA 私鑰

#HostKey /etc/ssh/ssh_host_dsa_key
##設置SSH version 2 使用的 DSA 私鑰


#Compression yes      
##設置是否可以使用壓縮指令

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
##KeyRegenerationInterval用來設置多長時間后系統自動重新生成服務器的秘鑰,
###(如果使用密鑰)。重新生成秘鑰是為了防止利用盜用的密鑰解密被截獲的信息。

#ServerKeyBits 768
##ServerKeyBits用來定義服務器密鑰的長度
###指定臨時服務器密鑰的長度。僅用於SSH-1。默認值是 768(位)。最小值是 512 。


# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
##SyslogFacility用來設定在記錄來自sshd的消息的時候,是否給出“facility code”

#LogLevel INFO
##LogLevel用來設定sshd日志消息的級別


#################3.安全認證方面的設定################
#############3.1、有關安全登錄的設定###############
# Authentication:
##限制用戶必須在指定的時限內認證成功,0 表示無限制。默認值是 120 秒。

#LoginGraceTime 2m
##LoginGraceTime用來設定如果用戶登錄失敗,在切斷連接前服務器需要等待的時間,單位為妙

#PermitRootLogin yes
##PermitRootLogin用來設置能不能直接以超級用戶ssh登錄,root遠程登錄Linux很危險,建議注銷或設置為no

#StrictModes yes
##StrictModes用來設置ssh在接收登錄請求之前是否檢查用戶根目錄和rhosts文件的權限和所有權,建議開啟
###建議使用默認值"yes"來預防可能出現的低級錯誤。

#RSAAuthentication yes
##RSAAuthentication用來設置是否開啟RSA密鑰驗證,只針對SSH1

#PubkeyAuthentication yes
##PubkeyAuthentication用來設置是否開啟公鑰驗證,如果使用公鑰驗證的方式登錄時,則設置為yes

#AuthorizedKeysFile     .ssh/authorized_keys
##AuthorizedKeysFile用來設置公鑰驗證文件的路徑,與PubkeyAuthentication配合使用,默認值是".ssh/authorized_keys"。
###該指令中可以使用下列根據連接時的實際情況進行展開的符號: %% 表示'%'、%h 表示用戶的主目錄、%u 表示該用戶的用戶名
####經過擴展之后的值必須要么是絕對路徑,要么是相對於用戶主目錄的相對路徑。

 

#############3.2、安全驗證的設定###############
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
##是否使用強可信主機認證(通過檢查遠程主機名和關聯的用戶名進行認證)。僅用於SSH-1。
###這是通過在RSA認證成功后再檢查 ~/.rhosts 或 /etc/hosts.equiv 進行認證的。出於安全考慮,建議使用默認值"no"。

# similar for protocol version 2
#HostbasedAuthentication no
##這個指令與 RhostsRSAAuthentication 類似,但是僅可以用於SSH-2。

# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication

#IgnoreUserKnownHosts no
##IgnoreUserKnownHosts用來設置ssh在進行RhostsRSAAuthentication安全驗證時是否忽略用戶的“/$HOME/.ssh/known_hosts”文件
# Don't read the user's ~/.rhosts and ~/.shosts files

#IgnoreRhosts yes
##IgnoreRhosts用來設置驗證的時候是否使用“~/.rhosts”和“~/.shosts”文件

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
##PasswordAuthentication用來設置是否開啟密碼驗證機制,如果用密碼登錄系統,則設置yes

#PermitEmptyPasswords no
#PermitEmptyPasswords用來設置是否允許用口令為空的賬號登錄系統,設置no

#PasswordAuthentication yes
##是否允許使用基於密碼的認證。默認為"yes"。
PasswordAuthentication yes

# Change to no to disable s/key passwords
##設置禁用s/key密碼
#ChallengeResponseAuthentication yes
##ChallengeResponseAuthentication 是否允許質疑-應答(challenge-response)認證
ChallengeResponseAuthentication no

 

########3.3、與 Kerberos 有關的參數設定,指定是否允許基於Kerberos的用戶認證########
#Kerberos options
#KerberosAuthentication no
##是否要求用戶為PasswdAuthentication提供的密碼必須通過Kerberos KDC認證,要使用Kerberos認證,
###服務器必須提供一個可以校驗KDC identity的Kerberos servtab。默認值為no

#KerberosOrLocalPasswd yes
##如果Kerberos密碼認證失敗,那么該密碼還將要通過其他的的認證機制,如/etc/passwd
###在啟用此項后,如果無法通過Kerberos驗證,則密碼的正確性將由本地的機制來決定,如/etc/passwd,默認為yes

#KerberosTicketCleanup yes
##設置是否在用戶退出登錄是自動銷毀用戶的ticket

#KerberosGetAFSToken no
##如果使用AFS並且該用戶有一個Kerberos 5 TGT,那么開啟該指令后,
###將會在訪問用戶的家目錄前嘗試獲取一個AFS token,並嘗試傳送 AFS token 給 Server 端,默認為no

 

####3.4、與 GSSAPI 有關的參數設定,指定是否允許基於GSSAPI的用戶認證,僅適用於SSH2####
##GSSAPI 是一套類似 Kerberos 5 的通用網絡安全系統接口。
###如果你擁有一套 GSSAPI庫,就可以通過 tcp 連接直接建立 cvs 連接,由 GSSAPI 進行安全鑒別。

# GSSAPI options
#GSSAPIAuthentication no
##GSSAPIAuthentication 指定是否允許基於GSSAPI的用戶認證,默認為no

GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes
##GSSAPICleanupCredentials 設置是否在用戶退出登錄是自動銷毀用戶的憑證緩存
GSSAPICleanupCredentials yes

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication mechanism.
# Depending on your PAM configuration, this may bypass the setting of
# PasswordAuthentication, PermitEmptyPasswords, and
# "PermitRootLogin without-password". If you just want the PAM account and
# session checks to run without PAM authentication, then enable this but set
# ChallengeResponseAuthentication=no
#UsePAM no
##設置是否通過PAM驗證
UsePAM yes

# Accept locale-related environment variables
##AcceptEnv 指定客戶端發送的哪些環境變量將會被傳遞到會話環境中。
###[注意]只有SSH-2協議支持環境變量的傳遞。指令的值是空格分隔的變量名列表(其中可以使用'*''?'作為通配符)。
####也可以使用多個 AcceptEnv 達到同樣的目的。需要注意的是,有些環境變量可能會被用於繞過禁止用戶使用的環境變量。
#####由於這個原因,該指令應當小心使用。默認是不傳遞任何環境變量。

AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL
AllowTcpForwarding yes

##AllowTcpForwarding設置是否允許允許tcp端口轉發,保護其他的tcp連接

#GatewayPorts no
##GatewayPorts 設置是否允許遠程客戶端使用本地主機的端口轉發功能,出於安全考慮,建議禁止

 

#############3.5、X-Window下使用的相關設定###############

#X11Forwarding no
##X11Forwarding 用來設置是否允許X11轉發
X11Forwarding yes

#X11DisplayOffset 10
##指定X11 轉發的第一個可用的顯示區(display)數字。默認值是 10 。
###可以用於防止 sshd 占用了真實的 X11 服務器顯示區,從而發生混淆。
X11DisplayOffset 10

#X11UseLocalhost yes

 

#################3.6、登入后的相關設定#################

#PrintMotd yes
##PrintMotd用來設置sshd是否在用戶登錄時顯示“/etc/motd”中的信息,可以選在在“/etc/motd”中加入警告的信息

#PrintLastLog yes
#PrintLastLog 是否顯示上次登錄信息

#TCPKeepAlive yes
##TCPKeepAlive 是否持續連接,設置yes可以防止死連接
###一般而言,如果設定這項目的話,那么 SSH Server 會傳送 KeepAlive 的訊息給 Client 端,以確保兩者的聯機正常!
####這種消息可以檢測到死連接、連接不當關閉、客戶端崩潰等異常。在這個情況下,任何一端死掉后, SSH 可以立刻知道,而不會有僵屍程序的發生!

#UseLogin no
##UseLogin 設置是否在交互式會話的登錄過程中使用。默認值是"no"。
###如果開啟此指令,那么X11Forwarding 將會被禁止,因為login不知道如何處理 xauth cookies 。
####需要注意的是,在SSH底下本來就不接受 login 這個程序的登入,如果指UsePrivilegeSeparation ,那么它將在認證完成后被禁用。
UserLogin no       

#UsePrivilegeSeparation yes
##UsePrivilegeSeparation 設置使用者的權限
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no

#UseDNS yes
##UseDNS是否使用dns反向解析

#PidFile /var/run/sshd.pid

#MaxStartups 10
##MaxStartups 設置同時允許幾個尚未登入的聯機,當用戶連上ssh但並未輸入密碼即為所謂的聯機,
###在這個聯機中,為了保護主機,所以需要設置最大值,預設為10個,而已經建立聯機的不計算入內,
####所以一般5個即可,這個設置可以防止惡意對服務器進行連接

#MaxAuthTries 6
##MaxAuthTries 用來設置最大失敗嘗試登陸次數為6,合理設置辭職,可以防止攻擊者窮舉登錄服務器
#PermitTunnel no

 

############3.7、開放禁止用戶設定############

#AllowUsers<用戶名1> <用戶名2> <用戶名3> ...
##指定允許通過遠程訪問的用戶,多個用戶以空格隔開

#AllowGroups<組名1> <組名2> <組名3> ...
##指定允許通過遠程訪問的組,多個組以空格隔開。當多個用戶需要通過ssh登錄系統時,可將所有用戶加入一個組中。

#DenyUsers<用戶名1> <用戶名2> <用戶名3> ...
##指定禁止通過遠程訪問的用戶,多個用戶以空格隔開

#DenyGroups<組名1> <組名2> <組名3> ...
##指定禁止通過遠程訪問的組,多個組以空格隔開。

# no default banner path
#Banner /some/path

# override default of no subsystems
Subsystem       sftp    /usr/libexec/openssh/sftp-server
ClientAliveInterval 3600
ClientAliveCountMax 0

 

 

 

 

 

 標准配置如下:

#       $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $ # This is the sshd server system-wide configuration file. See # sshd_config(5) for more information. # This sshd was compiled with PATH=/usr/local/bin:/usr/bin # The strategy used for options in the default sshd_config shipped with # OpenSSH is to specify options with their default value where # possible, but leave them commented. Uncommented options override the # default value. # If you want to change the port on a SELinux system, you have to tell # SELinux about this change. # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER    <==在開啟selinux的系統上,修改ssh端口的要修改selinux規則,用此命令修改 # #Port 22           <==默認ssh端口,生產環境中建議改成五位數的端口 #AddressFamily any <==地址家族,any表示同時監聽ipv4和ipv6地址 #ListenAddress 0.0.0.0  <==監聽本機所有ipv4地址 #ListenAddress :: <==監聽本機所有ipv6地址 HostKey /etc/ssh/ssh_host_rsa_key <==ssh所使用的RSA私鑰路徑 #HostKey /etc/ssh/ssh_host_dsa_key HostKey /etc/ssh/ssh_host_ecdsa_key <==ssh所使用的ECDSA私鑰路徑 HostKey /etc/ssh/ssh_host_ed25519_key <==ssh所使用的ED25519私鑰路徑 # Ciphers and keying #RekeyLimit default none # Logging #SyslogFacility AUTH SyslogFacility AUTHPRIV <==設定在記錄來自sshd的消息的時候,是否給出“facility code” #LogLevel INFO <==日志記錄級別,默認為info # Authentication: #LoginGraceTime 2m <==限定用戶認證時間為2min #PermitRootLogin yes <==是否允許root賬戶ssh登錄,生產環境中建議改成no,使用普通賬戶ssh登錄 #StrictModes yes <==設置ssh在接收登錄請求之前是否檢查用戶根目錄和rhosts文件的權限和所有權,建議開啟 #MaxAuthTries 6   <==指定每個連接最大允許的認證次數。默認值是 6 #MaxSessions 10   <==最大允許保持多少個連接。默認值是 10 #PubkeyAuthentication yes <==是否開啟公鑰驗證 # The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2 # but this is overridden so installations will only check .ssh/authorized_keys AuthorizedKeysFile .ssh/authorized_keys <==公鑰驗證文件路徑 #AuthorizedPrincipalsFile none #AuthorizedKeysCommand none #AuthorizedKeysCommandUser nobody # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts #HostbasedAuthentication no # Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication   <==指定服務器在使用 ~/.shosts ~/.rhosts /etc/hosts.equiv 進行遠程主機名匹配時,是否進行反向域名查詢 #IgnoreUserKnownHosts no <==是否在 RhostsRSAAuthentication 或 HostbasedAuthentication 過程中忽略用戶的 ~/.ssh/known_hosts 文件 # Don't read the user's ~/.rhosts and ~/.shosts files #IgnoreRhosts yes <==是否在 RhostsRSAAuthentication 或 HostbasedAuthentication 過程中忽略 .rhosts 和 .shosts 文件 # To disable tunneled clear text passwords, change to no here! #PasswordAuthentication yes #PermitEmptyPasswords no <==是否允許空密碼 PasswordAuthentication yes <==是否允許密碼驗證,生產環境中建議改成no,只用密鑰登錄 # Change to no to disable s/key passwords #ChallengeResponseAuthentication yes ChallengeResponseAuthentication no <==是否允許質疑-應答(challenge-response)認證 # Kerberos options #KerberosAuthentication no <==是否使用Kerberos認證 #KerberosOrLocalPasswd yes <==如果 Kerberos 密碼認證失敗,那么該密碼還將要通過其它的認證機制(比如 /etc/passwd) #KerberosTicketCleanup yes <==是否在用戶退出登錄后自動銷毀用戶的 ticket #KerberosGetAFSToken no <==如果使用了AFS並且該用戶有一個 Kerberos 5 TGT,那么開啟該指令后,將會在訪問用戶的家目錄前嘗試獲取一個AFS token #KerberosUseKuserok yes # GSSAPI options #GSSAPIAuthentication yes <==是否允許基於GSSAPI的用戶認證 GSSAPICleanupCredentials no <==是否在用戶退出登錄后自動銷毀用戶憑證緩存 #GSSAPIStrictAcceptorCheck yes #GSSAPIKeyExchange no #GSSAPIEnablek5users no # Set this to 'yes' to enable PAM authentication, account processing, # and session processing. If this is enabled, PAM authentication will # be allowed through the ChallengeResponseAuthentication and # PasswordAuthentication. Depending on your PAM configuration, # PAM authentication via ChallengeResponseAuthentication may bypass # the setting of "PermitRootLogin without-password". # If you just want the PAM account and session checks to run without # PAM authentication, then enable this but set PasswordAuthentication # and ChallengeResponseAuthentication to 'no'. # WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several # problems. UsePAM yes <==是否通過PAM驗證 #AllowAgentForwarding yes #AllowTcpForwarding yes #GatewayPorts no <==是否允許遠程主機連接本地的轉發端口 X11Forwarding yes <==是否允許X11轉發 #X11DisplayOffset 10  <==指定sshd(8)X11轉發的第一個可用的顯示區(display)數字。默認值是10 #X11UseLocalhost yes <==是否應當將X11轉發服務器綁定到本地loopback地址 #PermitTTY yes #PrintMotd yes <==指定sshd(8)是否在每一次交互式登錄時打印 /etc/motd 文件的內容 #PrintLastLog yes <==指定sshd(8)是否在每一次交互式登錄時打印最后一位用戶的登錄時間 #TCPKeepAlive yes <==指定系統是否向客戶端發送 TCP keepalive 消息 #UseLogin no <==是否在交互式會話的登錄過程中使用 login1UsePrivilegeSeparation sandbox <==是否讓 sshd(8) 通過創建非特權子進程處理接入請求的方法來進行權限分離 #PermitUserEnvironment no <==指定是否允許sshd(8)處理~/.ssh/environment以及 ~/.ssh/authorized_keys中的 environment= 選項 #Compression delayed <==是否對通信數據進行加密,還是延遲到認證成功之后再對通信數據加密 #ClientAliveInterval 0  <==sshd(8)長時間沒有收到客戶端的任何數據,不發送"alive"消息 #ClientAliveCountMax 3   <==sshd(8)在未收到任何客戶端回應前最多允許發送多個"alive"消息,默認值是 3 #ShowPatchLevel no #UseDNS no <==是否使用dns反向解析 #PidFile /var/run/sshd.pid   <==指定存放SSH守護進程的進程號的路徑 #MaxStartups 10:30:100   <==最大允許保持多少個未認證的連接 #PermitTunnel no <==是否允許tun(4)設備轉發 #ChrootDirectory none #VersionAddendum none # no default banner path #Banner none <==將這個指令指定的文件中的內容在用戶進行認證前顯示給遠程用戶,默認什么內容也不顯示,"none"表示禁用這個特性 # Accept locale-related environment variables AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE AcceptEnv XMODIFIERS # override default of no subsystems Subsystem sftp /usr/libexec/openssh/sftp-server <==配置一個外部子系統sftp及其路徑 # Example of overriding settings on a per-user basis #Match User anoncvs <==引入一個條件塊。塊的結尾標志是另一個 Match 指令或者文件結尾 # X11Forwarding no # AllowTcpForwarding no # PermitTTY no # ForceCommand cvs server ————————————————

 


免責聲明!

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



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