歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> BSD >> FreeBSD SSH配置詳解

FreeBSD SSH配置詳解

日期:2017/2/28 16:20:52   编辑:BSD

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 ~


下面對上述選項參數逐進行解釋:

# Site-wide defaults for various options
帶“#”表示該句為注釋不起作,該句不屬於配置文件原文,意在說明下面選項均為系統初始默認的選項。說明一下,實際配置文件中也有很多選項前面加有“#”注釋,雖然表示不起作用,

其實是說明此為系統默認的初始化設置。

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 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登錄。這個選項從安全角度來講應設成"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 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”的後面可以跟任意的數量的用戶名的匹配串,這些字符串用空格隔開。主機名可以是域名或IP地址。

幾點補充說明
1,如果重啟後還是不行請重新載入sshd_config 文件
/etc/rc.d/sshd reload
2,如果出現using keyboard-interactive authentication
password:
請確認PasswordAuthentication是否已經改成yes
另外如果客戶端是putty那麼請確認"嘗試'智能鍵盤'認證(SSH-2)"的勾是否有去掉
3,如果是使用root帳號登陸
請確認密碼是否為空
空密碼無法登陸
4請確認是否有安裝SSH
sysinstall>>>configure>>>networking>>>sshd是否的勾是否有打上

Copyright © Linux教程網 All Rights Reserved