歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 使用PuTTY密鑰認證機制遠程登錄Linux

使用PuTTY密鑰認證機制遠程登錄Linux

日期:2017/2/28 14:03:31   编辑:Linux教程

1、下載生成密鑰工具 putty工具包裡面的puttygen.exe
putty工具小巧攜帶方便,不需要安裝,可以百度免費下載使用。

2、雙擊打開puttygen.exe,右下角“Number of bits in a generated key”設置為2048 ,然後點擊“Generate”,開始生成密鑰,來回動一動鼠標,可以快速生成密鑰對。“Key comment”保持不變也可以自定義,對密鑰的簡單介紹;“Key passphrase”給密鑰設置密碼,下次使用遠程登錄只需要輸入這個密碼就可以登錄linux;“Confim passphrase”再次輸入剛剛設置的密碼。


3、保存私鑰,點擊"Save private key" 在彈出的浏覽框裡面選擇保存私鑰的地址,並命名方便區分。

4、復制公鑰到遠程linux裡面
回到密鑰生成的窗口,在“Key”下方的一堆字符串就是生成的公鑰內容,復制下來,粘貼到遠程linux /root/.ssh/authorized_keys 文件中。如果沒有.ssh目錄,需要自己建立一個,並更改目錄權限為700
[root@localhost ~]# mkdir /root/.ssh
[root@localhost ~]# chmod 700 /root/.ssh/
[root@localhost ~]# vi /root/.ssh/authorized_keys

粘貼公鑰的內容,保存退出。


5、關閉Selinux
如果不關閉Selinux,使用密鑰登錄會提示“Server refused our key”
關閉selinux有兩種方法:
暫時關閉selinux防火牆,下次重啟後selinux還會開啟。
#setenforce 0
#getenforce #查看臨時關閉selinux的狀態命令
永久關閉selinux
#vi /etc/selinux/config #修改selinux的配置文件
更改“SELINUX=enforcing”為 SELINUX=disabled 保存退出。
[root@localhost ~]# /usr/sbin/sestatus -v #查看selinux的狀態命令
SELinux status: disabled


6、關閉防火牆
[root@localhost ~]# iptables -F #清空防火牆配置
[root@localhost ~]# /etc/init.d/iptables save #清空防火牆配置後,記得保存
iptables:將防火牆規則保存到 /etc/sysconfig/iptables: [確定]


7、設置putty通過密鑰登錄
打開putty工具,選擇左側Connection——SSH——Auth 右側"Private key file for authentication" 點擊”Browse“選擇之前保存的私鑰文件。

8、使用密鑰驗證登錄遠程linux
打開putty界面,點擊左側”Session“會話窗口裡面”Host Name“下面填寫遠程linux的ip地址,”port“端口保持默認為22,”Connection type“保持默認為SSH,”Saved Sessions“下方可以命名會話,方便標示,填寫完成後點擊右邊的”Save“按鈕,下次登錄就不用再次輸入。下次登錄選擇保存的會話,點擊右邊的”Load“按鈕,加載設置,配置完成後點擊下方的”Open“打開登錄界面。
putty界面”Window“——Translation 選項,Remote character set:選擇UTF-8,避免出現亂碼;

root用戶登錄,輸入生成密鑰時設置的密碼,進入界面如下:
login as: root
Authenticating with public key "rsa-key-20150311"
Passphrase for key "rsa-key-20150311":
Last login: Wed Mar 11 19:26:27 2015 from 192.168.20.1
[root@localhost~]#

使用PuTTY時對原始設置的幾個簡單實用修改 http://www.linuxidc.com/Linux/2014-02/96924.htm

如何通過Putty實現遠程登錄控制Linux平台 http://www.linuxidc.com/Linux/2013-06/85266.htm

Putty連接VMWare中Ubuntu的問題解決 http://www.linuxidc.com/Linux/2013-05/84819.htm

VMware+Linux+Putty環境配置 http://www.linuxidc.com/Linux/2013-05/84818.htm

Copyright © Linux教程網 All Rights Reserved