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" 在彈出的浏覽框裡面選擇儲存私鑰的位址,并命名友善區分。
<a href="http://s3.51cto.com/wyfs02/M01/5B/22/wKiom1T_4BTTH4dyAALJKlSJf4w807.jpg" target="_blank"></a>
4、複制公鑰到遠端linux裡面
回到密鑰生成的視窗,在“Key”下方的一堆字元串就是生成的公鑰内容,複制下來,粘貼到遠端linux /root/.ssh/authorized_keys 檔案中。如果沒有.ssh目錄,需要自己建立一個,并更改目錄權限為700
1
2
3
<code>[root@localhost ~]</code><code># mkdir /root/.ssh</code>
<code>[root@localhost ~]</code><code># chmod 700 /root/.ssh/</code>
<code>[root@localhost ~]</code><code># vi /root/.ssh/authorized_keys</code>
粘貼公鑰的内容,儲存退出。
5、關閉Selinux
如果不關閉Selinux,使用密鑰登入會提示“Server refused our key”
關閉selinux有兩種方法:
暫時關閉selinux防火牆,下次重新開機後selinux還會開啟。
#setenforce 0
#getenforce #檢視臨時關閉selinux的狀态指令
永久關閉selinux
#vi /etc/selinux/config #修改selinux的配置檔案
更改“SELINUX=enforcing”為 SELINUX=disabled 儲存退出。
SELinux status: disabled
6、關閉防火牆
iptables:将防火牆規則儲存到 /etc/sysconfig/iptables: [确定]
7、設定putty通過密鑰登入
打開putty工具,選擇左側Connection——SSH——Auth 右側"Private key file for authentication" 點選”Browse“選擇之前儲存的私鑰檔案。
<a href="http://s3.51cto.com/wyfs02/M00/5B/22/wKiom1T_4ISiqRIBAAI4rdtZR8U330.jpg" target="_blank"></a>
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,避免出現亂碼;
<a href="http://s3.51cto.com/wyfs02/M02/5B/1C/wKioL1T_4dfDmg7WAAIhgPNWVTM731.jpg" target="_blank"></a>
root使用者登入,輸入生成密鑰時設定的密碼,進入界面如下:
4
5
<code>login as: root</code>
<code>Authenticating with public key </code><code>"rsa-key-20150311"</code>
<code>Passphrase </code><code>for</code> <code>key </code><code>"rsa-key-20150311"</code><code>:</code>
<code>Last login: Wed Mar 11 19:26:27 2015 from 192.168.20.1</code>
<code>[root@localhost~]</code><code>#</code>
<code></code><code></code>
<code></code><code>本文轉自 模範生 51CTO部落格,原文連結:http://blog.51cto.com/mofansheng/1619345,如需轉載請自行聯系原作者</code>
<code></code>