天天看點

linux ssh_config和sshd_config配置檔案

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

ssh_config和sshd_config都是ssh伺服器的配置檔案,二者差別在于,前者是針對用戶端的配置檔案,後者則是針對服務端的配置檔案。兩個配置檔案都允許你通過設定不同的選項來改變用戶端程式的運作方式。下面列出來的是兩個配置檔案中最重要的一些關鍵詞,每一行為“關鍵詞&值”的形式,其中“關鍵詞”是忽略大小寫的。

‍‍1、編輯 /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,由于rsh并不安全,是以此選項應當設定為"no"。

UseRsh no

"UseRsh"設定是否在這台計算機上使用"rlogin/rsh",原因同上,設為"no"。

BatchMode no

"BatchMode":批處理模式,一般設為"no";如果設為"yes",互動式輸入密碼的提示将被禁止,這個選項對腳本檔案和批處理任務十分有用。

CheckHostIP yes

"CheckHostIP"設定ssh是否檢視連接配接到伺服器的主機的IP位址以防止DNS欺騙。建議設定為"yes"。

StrictHostKeyChecking no

"StrictHostKeyChecking"如果設為"yes",ssh将不會自動把計算機的密匙加入"$HOME/.ssh/known_hosts"檔案,且一旦計算機的密匙發生了變化,就拒絕連接配接。

IdentityFile ~/.ssh/identity

"IdentityFile"設定讀取使用者的RSA安全驗證辨別。

Port 22

"Port"設定連接配接到遠端主機的端口,ssh預設端口為22。

Cipher blowfish

“Cipher”設定加密用的密鑰,blowfish可以自己随意設定。

EscapeChar ~

“EscapeChar”設定escape字元。

2、編輯 /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"設定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登入。這個選項從安全角度來講應設成"no"。

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”設定隻用rhosts或“/etc/hosts.equiv”進行安全驗證是否已經足夠了。

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

"RSAAuthentication”設定是否允許隻有RSA安全驗證。

"PasswordAuthentication”設定是否允許密碼驗證。

PermitEmptyPasswords no

"PermitEmptyPasswords”設定是否允許用密碼為空的帳号登入。

AllowUsers admin

"AllowUsers”的後面可以跟任意的數量的使用者名的比對串,這些字元串用空格隔開。主機名可以是域名或IP位址。

繼續閱讀