配置SSH“/etc/ssh/sshd_config”文件 分享


“/etc/ssh/sshd_config”是OpenSSH的配置文件,允許設置選項改變這個daemon的運行。這個文件的每一行包含“關鍵詞- 值”的匹配,其中“關鍵詞”是忽略大小寫的。下面列出來的是最重要的關鍵詞,用man命令查看幫助頁(sshd (8))可以得到詳細的列表。

編輯“sshd_config”文件(vi /etc/ssh/sshd_config),加入或改變下面的參數:

# This is ssh server systemwide configuration file.
Port 22
ListenAddress 192.168.1.1
HostKey /etc/ssh/ssh_host_key
ServerKeyBits 1024
LoginGraceTime 600
KeyRegenerationInterval 3600
PermitRootLogin no
IgnoreRhosts yes
IgnoreUserKnownHosts yes
StrictModes yes
X11Forwarding no
PrintMotd yes
SyslogFacility AUTH
LogLevel INFO
RhostsAuthentication no
RhostsRSAAuthentication no
RSAAuthentication yes
PasswordAuthentication yes
PermitEmptyPasswords no
AllowUsers admin

下面逐行說明上面的選項設置:

Port 22
   “Port”設置sshd監聽的端口號。

ListenAddress 192.168.1.1
   “ListenAddress”設置sshd服務器綁定的IP地址。

HostKey /etc/ssh/ssh_host_key

    “HostKey”設置包含計算機私人密匙的文件。

ServerKeyBits 1024
     “ServerKeyBits”定義服務器密匙的位數。

LoginGraceTime 600
     “LoginGraceTime”設置如果用戶不能成功登錄,在切斷連接之前服務器需要等待的時間(以秒為單位)。

KeyRegenerationInterval 3600
    “KeyRegenerationInterval”設置在多少秒之后自動重新生成服務器的密匙(如果使用密匙)。重新生成密匙是為了防止用盜用的密匙解密被截獲的信息。

PermitRootLogin no
   “PermitRootLogin”設置root能不能用ssh登錄。這個選項一定不要設成“yes”。

IgnoreRhosts yes
   “IgnoreRhosts”設置驗證的時候是否使用“rhosts”和“shosts”文件。

IgnoreUserKnownHosts yes
    “IgnoreUserKnownHosts”設置ssh daemon是否在進行RhostsRSAAuthentication安全驗證的時候忽略用戶的“$HOME/.ssh/known_hosts”

StrictModes yes
     “StrictModes”設置ssh在接收登錄請求之前是否檢查用戶家目錄和rhosts文件的權限和所有權。這通常是必要的,因為新手經常會把自己的目錄和文件設成任何人都有寫權限。

X11Forwarding no
      “X11Forwarding”設置是否允許X11轉發。

PrintMotd yes
      “PrintMotd”設置sshd是否在用戶登錄的時候顯示“/etc/motd”中的信息。

SyslogFacility AUTH
      “SyslogFacility”設置在記錄來自sshd的消息的時候,是否給出“facility code”。

LogLevel INFO
      “LogLevel”設置記錄sshd日志消息的層次。INFO是一個好的選擇。查看sshd的man幫助頁,已獲取更多的信息。

RhostsAuthentication no
     “RhostsAuthentication”設置只用rhosts或“/etc/hosts.equiv”進行安全驗證是否已經足夠了。

RhostsRSAAuthentication no
     “RhostsRSA”設置是否允許用rhosts或“/etc/hosts.equiv”加上RSA進行安全驗證。

RSAAuthentication yes
      “RSAAuthentication”設置是否允許只有RSA安全驗證。

PasswordAuthentication yes
      “PasswordAuthentication”設置是否允許口令驗證。

PermitEmptyPasswords no
      “PermitEmptyPasswords”設置是否允許用口令為空的帳號登錄。

AllowUsers admin
      “AllowUsers”的后面可以跟着任意的數量的用戶名的匹配串(patterns)或user@host這樣的匹配串,這些字符串用空格隔開。主機名可以是DNS名或IP地址。


免責聲明!

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



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