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

從夢想照進現實的博客轉載shell

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.
cookie

# 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.
session

#############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
ssh

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

##設置SSH version 1 使用的私鑰ide

# 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.一、有關安全登陸的設定###############
# 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.二、安全驗證的設定###############
# 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.三、與 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.四、與 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.五、X-Window下使用的相關設定###############

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

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

#X11UseLocalhost yes

 

#################3.六、登入後的相關設定#################

#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.七、開放禁止用戶設定############

#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 subsystemsSubsystem       sftp    /usr/libexec/openssh/sftp-serverClientAliveInterval 3600ClientAliveCountMax 0

相關文章
相關標籤/搜索