歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> Linux系統中OpenSSH的安裝和配置之二

Linux系統中OpenSSH的安裝和配置之二

日期:2017/2/27 14:14:32   编辑:更多Linux
  配置 可以 到這去下載 “floppy.tgz”文件。把“floppy.tgz”文件解開之後,可以在相應的目錄下發現我們在這本書中介紹的所有軟件的配置文件。這樣就沒有必要手工重新生成這些文件,或者用拷貝粘貼的方法把它們粘貼到配置文件中去。不管是打算自己動手生成配置文件還是拷貝現成的,你都要學會自己修改配置文件並且把配置文件拷貝到正確的目錄下。下面將具體說明。 為了運行OpenSSH,必須創建或者把下面的文件拷貝到相應的目錄下: l 把“sshd_config”文件拷貝到“/etc/ssh”目錄下 l 把“ssh_config”文件拷貝到“/etc/ssh”目錄下 l 把“ssh”文件拷貝到“/etc/pam.d/”目錄下 可以把“floppy.tgz”解壓之後,找到上面列出來的文件,並拷貝到合適的目錄下,或者用拷貝粘貼的方法從本書中直接粘貼出。 配置“/etc/ssh/ssh_config”文件 “/etc/ssh/ssh_config”文件是OpenSSH系統范圍的配置文件,允許你通過設置不同的選項來改變客戶端程序的運行方式。這個文件的每一行包含“關鍵詞-值”的匹配,其中“關鍵詞”是忽略大小寫的。下面列出來的是最重要的關鍵詞,用man命令查看幫助頁(ssh (1))可以得到詳細的列表。 編輯“ssh_config”文件(vi /etc/ssh/ssh_config),添加或改變下面的參數: # Site-wide defaults for various options Host * ForwardAgent no ForwardX11 no RhostsAuthentication no RhostsRSAAuthentication no RSAAuthentication yes PassWordAuthentication yes FallBackToRsh no UseRsh no BatchMode no CheckHostIP yes StrictHostKeyChecking no IdentityFile ~/.ssh/identity Port 22 Cipher blowfish EscapeChar ~ 下面逐行說明上面的選項設置: Host * 選項“Host”只對能夠匹配後面字串的計算機有效。“*”表示所有的計算機。 ForwardAgent no “ForwardAgent”設置連接是否經過驗證代理(如果存在)轉發給遠程計算機。 ForwardX11 no “ForwardX11”設置X11連接是否被自動重定向到安全的通道和顯示集(DISPLAY set)。 RhostsAuthentication no “RhostsAuthentication”設置是否使用基於rhosts的安全驗證。 RhostsRSAAuthentication no “RhostsRSAAuthentication”設置是否使用用RSA算法的基於rhosts的安全驗證。 RSAAuthentication yes “RSAAuthentication”設置是否使用RSA算法進行安全驗證。 PasswordAuthentication yes “PasswordAuthentication”設置是否使用口令驗證。 FallBackToRsh no “FallBackToRsh”設置如果用ssh連接出現錯誤是否自動使用rsh。 UseRsh no “UseRsh”設置是否在這台計算機上使用“rlogin/rsh”。 BatchMode no “BatchMode”如果設為“yes”,passphrase/password(交互式輸入口令)的提示將被禁止。當不能交互式輸入口令的時候,這個選項對腳本文件和批處理任務十分有用。 CheckHostIP yes “CheckHostIP”設置ssh是否查看連接到服務器的主機的IP地址以防止DNS欺騙。建議設置為“yes”。


StrictHostKeyChecking no “StrictHostKeyChecking”如果設置成“yes”,ssh就不會自動把計算機的密匙加入“$HOME/.ssh/known_hosts”文件,並且一旦計算機的密匙發生了變化,就拒絕連接。 IdentityFile ~/.ssh/identity “IdentityFile”設置從哪個文件讀取用戶的RSA安全驗證標識。 Port 22 “Port”設置連接到遠程主機的端口。 Cipher blowfish “Cipher”設置加密用的密碼。 EscapeChar ~ “EscapeChar”設置escape字符。 配置“/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地址。



RSAAuthentication yes “RSAAuthentication”設置是否允許只有RSA安全驗證。 PasswordAuthentication yes “PasswordAuthentication”設置是否允許口令驗證。 PermitEmptyPasswords no “PermitEmptyPasswords”設置是否允許用口令為空的帳號登錄。 AllowUsers admin “AllowUsers”的後面可以跟著任意的數量的用戶名的匹配串(patterns)或user@host這樣的匹配串,這些字符串用空格隔開。主機名可以是DNS名或IP地址。



Copyright © Linux教程網 All Rights Reserved