SSH由用戶端和服務端的軟體組成,在用戶端可以使用的軟體有SecureCRT、putty、Xshell等,
而在伺服器端運作的是一個sshd的服務,通過使用SSH,可以把所有傳輸的資料進行加密,而且也能夠
防止dns和IP欺騙,此外,SSH傳輸的資料是經過壓縮的,可以加快傳輸速度
其伺服器端的配置檔案為/etc/ssh/sshd_config
[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.11 及 192.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
##是否允許使用基于密碼的認證。預設為"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