ssh的英文全稱是Secure SHell,這是一種既能夠代替telnet,又能夠爲ftp、pop、甚至ppp提供一個安全的"通道"。ssh有不少的參數,下面就來介紹兩個比較經常使用的參數html
PermitRootLogin prohibit-password 這個參數的意思是否容許遠程root登錄,默認是禁止遠程root密碼登錄,如果須要遠程root登錄,就須要把這個更改成yeslinux
PasswordAuthentication 這個參數是用來定義是否容許用密碼登錄,這個在通常的狀況下是yes,固然也有no狀況shell
其餘的參數設置參考這篇文檔安全
###通常在ssh會遇到的問題服務器
# ssh 172.16.81.221 ssh: connect to host 172.16.81.221 port 22: No route to host
這因爲server端沒有開機或是網絡不通,或者是主機down了網絡
# ssh work@172.16.81.221 ssh: connect to host 172.16.81.221 port 22: Connection refused
這是由於對方的ssh服務沒有開,開啓對端sever的ssh便可ssh
# ssh 172.16.81.221 root@172.16.81.221's password: Permission denied, please try again.
這是因爲在不輸入用戶名的狀況下,默認是root用戶登錄,結果多是對端不容許root登錄.tcp
ssh root@172.16.81.221 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that the RSA host key has just been changed. The fingerprint for the RSA key sent by the remote host is 76:fb:b3:70:14:48:19:d6:29:f9:ba:42:46:be:fb:77. Please contact your system administrator. Add correct host key in /home/fante/.ssh/known_hosts to get rid of this message. Offending key in /home/fante/.ssh/known_hosts:68 RSA host key for 172.16.81.221 has changed and you have requested strict checking. Host key verification failed
這是由於對端密碼或是ip對應的server等其餘發生改變,與當前的不一致致使的,刪除~/.ssh/known_hosts的對應行,而後再登陸便可。this
Xshell:\> ssh 121.207.***.*** Connecting to 121.207.***.***:22... Connection established. To escape to local shell, press 'Ctrl+Alt+]'. Connection closed by foreign host. Type `help' to learn how to use Xshell prompt.
在服務器上重啓sshd服務時,有WARNNING的,可是,sshd服務是能夠啓動的,那麼,問題可能 出如今/etc/ssh/下面文件權限不對致使的,能夠找一個可使用的,而後對比一下,就能夠發現其中的區別了。code
###限制登錄服務器
sshd:ALL
增長:/etc/hosts.allow 文件,
sshd:192.168.10.0/255.255.255.0(准許的網段)
或者是
sshd:192.168.10.1(准許的ip)
而後重啓ssh服務,這兩個文件是tcpd的配置文件,tcpd能夠控制外部ip對本機的訪問,經過他能夠容許或者拒絕某個ip或者ip段的客戶訪問linux的某項服務。ALL匹配全部狀況,EXCEPT匹配除了某些項以外的狀況,PARANOID匹配你想控制的IP地址和它的域名不匹配時(域名假裝)的狀況。在兩個配置文件有衝突時,linux 系統會先檢查/etc/hosts.deny規則,再檢查/etc/hosts.allow規則,若是有衝突 按/etc/hosts.allow規則處理。
AllowUsers root@192.168.1.0/24