推薦使用man sshd_config指令獲取配置文件詳細說明
Port 22
AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::
Protocol 2
/*
Port:sshd服務端口,預設22,也可以開放多個端口
AddressFamily:使用地址族,any(默認)、inet(僅IPv4)、inet6(僅IPv6)
ListenAddress:設置監聽的地址
Protocol:SSH協議版本
*/
# HostKey for protocol version 1
HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
/*
主機私鑰存放位置
*/
KeyRegenerationInterval 1h
ServerKeyBits 1024
/*
對于SSH-1協議中秘鑰的過期時間和大小
*/
# Logging
SyslogFacility AUTH
SyslogFacility AUTHPRIV
LogLevel INFO
/*
SyslogFacility:日志系統選擇
LogLevel:日志等級選擇
*/
# Authentication:
LoginGraceTime 2m
PermitRootLogin yes
StrictModes yes
MaxAuthTries 6
MaxSessions 10
/*
LoginGraceTime:限制認證時限
PermitRootLogin:允許ROOT賬戶登錄
StrictModes:檢查用戶主目錄和相關的配置文件
MaxAuthTries:最大認證次數
MaxSessions:最大保持連接數
*/
RSAAuthentication yes
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
/*
RSAAuthentication:SSH-1公鑰認證
PubkeyAuthentication:SSH-2公鑰認證
AuthorizedKeysFile:授權秘鑰文件
*/
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
/*
RhostsRSAAuthentication:SSH-1強可信主機
HostbasedAuthentication:SSH-2強可信主機
IgnoreUserKnownHosts:認證過程中忽略用戶的 ~/.ssh/known_hosts 文件
IgnoreRhosts:認證過程中忽略 .rhosts 和 .shosts 文件
*/
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
PermitEmptyPasswords no
/*
PasswordAuthentication:使用密碼認證
PermitEmptyPasswords:允許密碼為空賬戶登錄
*/
# Change to no to disable s/key passwords
ChallengeResponseAuthentication yes
/*
ChallengeResponseAuthentication:是否允許質疑-應答(challenge-response)認證
*/
# Kerberos options
KerberosAuthentication no
KerberosOrLocalPasswd yes
KerberosTicketCleanup yes
KerberosGetAFSToken no
/*
KerberosAuthentication:是否使用Kerberos認證
KerberosOrLocalPasswd:如果 Kerberos 密碼認證失敗,那么該密碼還將要通過其它的認證機制
KerberosTicketCleanup:是否在用戶退出登錄后自動銷毀用戶的 ticket
KerberosGetAFSToken:嘗試獲取一個 AFS token
*/
# GSSAPI options
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
GSSAPIStrictAcceptorCheck yes
/*
GSSAPIAuthentication:是否允許使用基于 GSSAPI 的用戶認證
GSSAPICleanupCredentials:是否在用戶退出登錄后自動銷毀用戶憑證緩存
GSSAPIStrictAcceptorCheck:是否嚴格檢查GSSAPI的用戶認證
*/
# 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
/*
UsePAM:是否使用PAM認證登錄
*/
AllowAgentForwarding yes
AllowTcpForwarding yes
GatewayPorts no
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes
PermitTTY yes
PrintMotd yes
PrintLastLog yes
TCPKeepAlive yes
UseLogin no
UsePrivilegeSeparation sandbox # Default for new installations.
PermitUserEnvironment no
Compression delayed
ClientAliveInterval 0
ClientAliveCountMax 3
ShowPatchLevel no
UseDNS yes
PidFile /var/run/sshd.pid
MaxStartups 10:30:100
PermitTunnel no
ChrootDirectory none
VersionAddendum none
/*
AllowAgentForwarding:是否允許轉發ssh-agent
AllowTcpForwarding:是否允許TCP轉發
GatewayPorts:是否允許遠程主機連接本地的轉發端口
X11Forwarding:是否允許進行 X11 轉發
X11DisplayOffset:指定X11 轉發的第一個可用的顯示區(display)數字
X11UseLocalhost:是否應當將X11轉發服務器綁定到本地loopback地址
PermitTTY:是否允許pty分配
PrintMotd:是否在每一次交互式登錄時打印 /etc/motd 文件的內容
PrintLastLog:是否在每一次交互式登錄時打印最后一位用戶的登錄時間
TCPKeepAlive:是否向客戶端發送 TCP keepalive 消息
UseLogin:是否在交互式會話的登錄過程中使用 login
UsePrivilegeSeparation:是否讓 sshd 通過創建非特權子進程處理接入請求的方法來進行權限分離
PermitUserEnvironment:是否允許 sshd處理environment
Compression:是否對通信數據進行加密
ClientAliveInterval:設置一個以秒記的時長,向客戶端發送一個”alive”消息,并等候應答
ClientAliveCountMax:sshd 在未收到任何客戶端回應前最多允許發送多少個”alive”消息
ShowPatchLevel:是否顯示ssh的補丁信息
UseDNS:是否應該對遠程主機名進行反向解析
PidFile:pid文件位置
MaxStartups: 指定并發未認證的最大數量節點到SSH守護進程
PermitTunnel:是否允許 tun 設備轉發
ChrootDirectory:指定chroot認證的路徑名
VersionAddendum:連接時指定附加文本
*/
# no default banner path
Banner none
/*
Banner:將這個指令指定的文件中的內容在用戶進行認證前顯示給遠程用戶
*/
# 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
/*
AcceptEnv:指定客戶端發送的哪些環境變量將會被傳遞到會話環境中
*/
# override default of no subsystems
Subsystem sftp /usr/libexec/openssh/sftp-server
/*
Subsystem:配置一個外部子系統
*/
NOTE:
1、 以上的所有說明配置命令均已去掉‘#’(注釋符號),請勿直接copy使用
2、 在修改sshd_config文件時,正確的姿勢應該是在原配置文件中找到相關配置添加‘#’注釋,再在文件末尾添加配置命令及選項
3、以上內容并不完全來自于自己翻譯,有部分摘自網絡內容,如有侵權行為,請告知E-mail:gaohanxiang@126.com,本人會第一時間刪除