系統環境是centos7,虛擬機環境下的。在使用ssh工具連接虛擬機的時候發現連接不上,用的是root
先檢查openssh-server是否安裝:
yum list installed | grep openssh-server
查看日志/var/log/secure:
顯示相關的錯誤內容:
PAM 1 more authentication failure; logname =uid=0 euid=0 tty=ssh ruser= rhost=……
pam_unix(login:session) :session closed for user root
沒有發現什么有用的信息
查看22端口是否開啟監聽:
netstat -an | grep 22
發現沒有listen,那么就是配置文件的問題了,
打開/etc/ssh/sshd_config
將選項中的Port 22取消注釋,還有ListenAddress 0.0.0.0 ListenAddress ::也取消注釋,這些設置分別為監聽端口、監聽地址
把PermitRootLogin no 的no改為yes(允許root開啟遠程登錄)
PasswordAuthentication 設置為yes(開啟使用用戶名和密碼作為連接驗證)
(如果是ubuntu,找到 GSSAPI options 這一節,將下面兩行注釋掉:
#GSSAPIAuthentication yes #GSSAPIDelegateCredentials no 然后重新啟動)
退出后重啟sshd,service sshd restart
同時要確保虛擬機系統和主機是通過局域網下的,能互相ping通的
將ssh設為自啟動:
systemctl enable sshd.service
檢測ssh是否為自啟動:
systemctl list-unit-files | grep sshd