<a href="http://www.itchenyi.com/wp-content/uploads/2012/12/openssh.gif"></a>
說明:
伺服器IP:192.168.1.200
管理者賬号:root 密碼:chenyi
普通登入賬号: itchenyi.com 密碼:chenyi
實作目的:
1、配置普通賬号通過密鑰驗證遠端SSH登入伺服器
2、禁用root賬号通過遠端SSH登入伺服器
3、禁用所有賬号通過密碼驗證遠端SSH登入伺服器
具體操作:
使用普通賬号itchenyi.com登入伺服器操作
ssh-keygen -t rsa #生成密鑰
[itchenyi.com@chenyi ~]$ cd /home/itchenyi.com/.ssh/ #進入目錄
[itchenyi.com@chenyi ~]$ mv id_rsa.pub authorized_keys #生成驗證檔案
下載下傳伺服器/root/.ssh/id_rsa檔案到本地(這裡采用flashfxp工具下載下傳)
<a href="http://www.itchenyi.com/wp-content/uploads/2012/12/sshkeys0.jpg"></a>
打開puttygen.exe
選擇Conversions-Import key打開上一步下載下傳到本地的檔案id_rsa
<a href="http://www.itchenyi.com/wp-content/uploads/2012/12/sshkeys1.jpg"></a>
點Save private key,根據提示選擇“是”,最後儲存為id_rsa.ppk
<a href="http://www.itchenyi.com/wp-content/uploads/2012/12/sshkeys2.jpg"></a>
2、禁止root通過SSH遠端登入伺服器、禁用所有賬号通過密碼驗證遠端SSH登入伺服器
下面為有效配置,其中隻修改了3個點,可針對你的環境自行設定
:wq! #儲存退出
/etc/init.d/sshd restart #重新開機SSH服務
3、打開putty.exe 使用root賬戶登入,出現報錯,此時肯定無法直接登入
4、實作普通賬戶itchenyi.com通過密鑰驗證遠端SSH登入伺服器
打開putty.exe,切換到Connection → SSH → Auth,點Browse...
選擇前面儲存的id_rsa.ppk檔案
<a href="http://www.itchenyi.com/wp-content/uploads/2012/12/sshkeys3.jpg"></a>
再切換到Connection-Data,Auto-login username輸入itchenyi.com
<a href="http://www.itchenyi.com/wp-content/uploads/2012/12/sshkeys4.jpg"></a>
再切換到Session,Host Name 輸入192.168.21.131 Port為22(如果修改過ssh端口的請填寫相應端口)
<a href="http://www.itchenyi.com/wp-content/uploads/2012/12/sshkeys5.jpg"></a>
配置完成之後,最後點Open,現在已經登入到系統了!
su - root #切換到root使用者,根據提示輸入密碼
如下圖所示
<a href="http://www.itchenyi.com/wp-content/uploads/2012/12/sshkeys6.jpg"></a>
至此,配置Linux伺服器SSH遠端密鑰登入完成!
如果你做法和我一模一樣,結果你登入不上去,哈哈,你有關掉iptables或者加上那一條政策嗎。呵呵呵~~~
本文轉自 lgpqdwjh 51CTO部落格,原文連結:http://blog.51cto.com/itchenyi/1110042,如需轉載請自行聯系原作者