2012年2月3日 星期五

ssh 設定範本

以下為OpenSSH的伺服器端設定檔sshd_config簡易說明
------------------------------------------------------------------------------------------------------------
# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
# SSH 預設使用 22 這個port,也可以使用多個port,即重複使用 port 這個設定項目!
# 例如想要開放 sshd 在 22 與 443 ,則多加一行內容為:『 Port 443 』
# 然後重新啟動 sshd 這樣就好了!不過,不建議修改 port number 啦!
Port 22

# Use these options to restrict which interfaces/protocols sshd will bind to
# 監聽的主機介面卡!舉個例子來說,如果你有兩個 IP,分別是 192.168.1.100 及 
# 192.168.100.254,假設你只想要讓 192.168.1.100 可以監聽 sshd ,那就這樣寫:
# 『 ListenAddress 192.168.1.100 』預設值是監聽所有介面的 SSH 要求
#ListenAddress ::
#ListenAddress 0.0.0.0

# 選擇的 SSH 協定版本,可以是 1 也可以是 2 ,CentOS 5.x 預設是僅支援 V2。
# 如果想要支援舊版 V1 ,就得要使用『 Protocol 2,1 』才行。
Protocol 2

# 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 私鑰
HostKey /etc/ssh/ssh_host_ecdsa_key

#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 768

# Logging
# 當有人使用 SSH 登入系統的時候,SSH 會記錄資訊,這個資訊要記錄在什麼 daemon name
# 底下?預設是以 AUTH 來設定的,即是 /var/log/secure 裡面!其他可用的 daemon name 為:DAEMON,USER,AUTH,LOCAL0,LOCAL1,LOCAL2,LOCAL3,LOCAL4,LOCAL5,
SyslogFacility AUTH

# 登錄記錄的等級
LogLevel INFO

# Authentication:
## 當使用者連上 SSH server 之後,會出現輸入密碼的畫面,在該畫面中,
# 在多久時間內沒有成功連上 SSH server 就強迫斷線!若無單位則預設時間為秒!
LoginGraceTime 120

# 是否允許 root 登入!預設是允許的
PermitRootLogin no

# 是否讓 sshd 去檢查使用者家目錄或相關檔案的權限資料,
# 這是為了擔心使用者將某些重要檔案的權限設錯,可能會導致一些問題所致。
# 例如使用者的 ~.ssh/ 權限設錯時,某些特殊情況下會不許用戶登入
StrictModes yes

# 是否允許用戶自行使用成對的金鑰系統進行登入行為,僅針對 version 2。
# 至於自製的公鑰資料就放置於使用者家目錄下的 .ssh/authorized_keys 內
RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
# 是否允許以空的密碼登入
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10

# 登入後是否顯示出一些資訊呢?例如上次登入的時間、地點等等,預設是 yes
# 亦即是列印出 /etc/motd 這個檔案的內容。但是,如果為了安全,可以考慮改為 no !
PrintMotd no

# 顯示上次登入的資訊!可以啊!預設也是 yes !
PrintLastLog yes

# 當達成連線後,伺服器會一直傳送 TCP 封包給用戶端藉以判斷對方式否一直存在連線。
# 不過,如果連線時中間的路由器暫時停止服務幾秒鐘,也會讓連線中斷喔!
# 在這個情況下,任何一端死掉後,SSH可以立刻知道!而不會有僵屍程序的發生!
# 但如果你的網路或路由器常常不穩定,那麼可以設定為 no 的啦!
TCPKeepAlive yes

#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

# 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'.
UsePAM yes

UseDNS no