SSH遠程登錄配置文件sshd_config詳解


轉載自http://blog.51cto.com/lookingdream/1826618

SSH由客戶端和服務端的軟件組成,在客戶端可以使用的軟件有SecureCRT、putty、Xshell等,
而在服務器端運行的是一個sshd的服務,通過使用SSH,可以把所有傳輸的數據進行加密,而且也能夠
防止dns和IP欺騙,此外,SSH傳輸的數據是經過壓縮的,可以加快傳輸速度

其服務器端的配置文件為/etc/ssh/sshd_config

  遠程管理linux系統基本上都要使用到ssh,原因很簡單:telnet、FTP等傳輸方式是?以明文傳送用戶認證信息,本質上是不安全的,存在被網絡竊聽的危險。SSH(Secure Shell)目前較可靠,是專為遠程登錄會話和其他網絡服務提供安全性的協議。利用SSH協議可以有效防止遠程管理過程中的信息泄露問題,透過SSH可以對所有傳輸的數據進行加密,也能夠防止DNS欺騙和IP欺騙。

 
 ssh_config和sshd_config都是ssh服務器的配置文件,二者區別在於,前者是針對客戶端的配置文件,后者則是針對服務端的配置文件。兩個配置文件都允許你通過設置不同的選項來改變客戶端程序的運行方式。

 

[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  //地址家族,any表示同時監聽ipv4和ipv6地址
#ListenAddress 0.0.0.0  //監聽本機所有ipv4地址

#ListenAddress ::          //監聽本機所有ipv6地址
#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所使用的RSA私鑰路徑
##設置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


免責聲明!

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



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