標籤:方式 strong try tar 錯誤資訊 continue you can man
SSH(Secure Shell)是一種能夠以安全的方式提供遠程登入的協議,想要使用 SSH 協議來遠端管理 Linux 系統,則需要部署配置 sshd 服務程式。sshd 是基於 SSH
協議開發的一款遠端管理服務程式,不僅使用起來方便快捷,而且能夠提供兩種安全驗證的方法:
? 基於口令的驗證—用賬戶和密碼來驗證登入;
? 基於密鑰的驗證—需要在本地產生金鑰組,然後把金鑰組中的公開金鑰上傳至伺服器,
並與伺服器中的公開金鑰進行比較;該方式相較來說更安全。
sshd 服務的配置資訊儲存在/etc/ssh/sshd_config 檔案中。儲存著最主要配置資訊的檔案稱為主設定檔,(一般的設定檔在 /etc/服務名稱/服務名稱.conf 中)而設定檔中有許多以
井號開頭的注釋行,要想讓這些配置參數生效,需要在修改參數後再去掉前面的井號。
sshd 服務組態檔中包含的參數以及作用
參數 |
作用 |
Port 22 |
預設的 sshd 服務 |
ListenAddress 0.0.0.0 |
設定 sshd 伺服器監聽的 IP 位址 |
Protocol 2 |
SSH 協議的版本號碼 |
HostKey /etc/ssh/ssh_host_key |
SSH 協議版本為 1 時,DES 私密金鑰存放的位置 |
HostKey /etc/ssh/ssh_host_rsa_key |
SSH 協議版本為 2 時,RSA 私密金鑰存放的位置 |
HostKey /etc/ssh/ssh_host_dsa_key |
SSH 協議版本為 2 時,DSA 私密金鑰存放的位置 |
PermitRootLogin yes |
設定是否允許 root 管理員直接登入 |
StrictModes yes |
當遠端使用者的私密金鑰改變時直接拒絕串連 |
MaxAuthTries 6 |
最大密碼嘗試次數 |
MaxSessions 10 |
最大終端數 |
PasswordAuthentication yes |
是否允許密碼驗證 |
PermitEmptyPasswords no |
是否允許空密碼登入(很不安全) |
在 RHEL 7 系統中,已經預設安裝並啟用了 sshd 服務程式。接下來使用 ssh 命令進行遠端連線,其格式為“ssh [參數] 主機 IP 位址”。要退出登入則執行 exit 命令。
[[email protected] Desktop]# ssh 192.168.10.10The authenticity of host ‘192.168.10.10 (192.168.10.10)‘ can‘t be established.ECDSA key fingerprint is 35:01:64:40:4c:22:41:f1:2e:2c:75:76:a3:14:47:40.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added ‘192.168.10.10‘ (ECDSA) to the list of known hosts.[email protected]192.168.10.10‘s password: 此處輸入密碼Last login: Tue Oct 2 16:26:24 2018[[email protected] ~]# exitlogoutConnection to 192.168.10.10 closed.[[email protected] Desktop]#
禁止root管理員的身份登入
首先使用 Vim 文字編輯器開啟 sshd 服務的主設定檔,然後把第 48 行#PermitRootLogin yes 參數前的井號(#)去掉,並把參數值 yes 改成 no,這樣就不再
允許 root 管理員遠程登入了。
[[email protected] Desktop]# vim /etc/ssh/sshd_config
………………省略部分輸出資訊………………47 #LoginGraceTime 2m 48 PermitRootLogin no 49 #StrictModes yes 50 #MaxAuthTries 6 51 #MaxSessions 10
………………省略部分輸出資訊………………
一般的服務程式並不會在設定檔修改之後立即獲得最新的參數。如果想讓新設定檔生效,則需要手動重啟相應的服務程式。最好也將這個服務程式加入到開機
啟動項中,這樣系統在下一次啟動時,該服務程式便會自動運行,繼續為使用者提供服務。
[[email protected] Desktop]# systemctl restart sshd[[email protected] Desktop]# systemctl enable sshd
當 root 管理員再來嘗試訪問 sshd 服務程式時,系統會提示不可訪問的錯誤資訊。
[[email protected] Desktop]# ssh 192.168.10.10[email protected]192.168.10.10‘s password: Permission denied, please try again.
紅帽7 ssh