CentOS下配置SSH密鑰遠程登陸

來源:互聯網
上載者:User

大致步驟:在伺服器端產生一對密鑰,然後公開金鑰儲存在伺服器使用者目錄.ssh下的authorized_keys2,是個隱藏的目錄。私密金鑰必須將id_dsa下載到用戶端,然後通過puttygen.exe產生.ppk檔案。當使用者登入時,伺服器會根據公開金鑰來比較私密金鑰,如果相符就允許登陸,否則拒絕。私密金鑰只儲存在用戶端中,及時有人知道root密碼,沒有私密金鑰也不能遠程登入到伺服器上。

Centos 5.4 ssh key 配置:

1. Server:

1).shell# vi /etc/ssh/sshd_config 修改以下配置:

Port 20000

Protocol 2

PasswordAuthentication no

2).#為了安全起見,ssh key方式用普通使用者登入,例如smallfish

[smallfish@tingso ~]$ ssh-keygen -t dsa

Generating public/private dsa key pair.

Enter file in which to save the key (/home/smallfish/.ssh/id_dsa):

Created directory '/home/smallfish/.ssh'.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/smallfish/.ssh/id_dsa.

Your public key has been saved in /home/smallfish/.ssh/id_dsa.pub.

The key fingerprint is:

68:e2:be:31:5a:d0:3c:0f:6d:48:31:69:13:9c:58:f3 smallfish@tingso.com

3).shell$ chmmod o+x /home/smallfish

[smallfish@tingso .ssh]$ ls

id_dsa id_dsa.pub

4).mv id_dsa.pub authorized_keys2

5).download id_dsa to windows #一般為了方便下載到putty目錄下,用於產生ppk檔案

6).shell# service sshd restart

2. Client:

#產生ppk檔案

1).open puttygen.exe--Conversions--import key--id_dsa--Enter passpharase for key--Save private key--儲存為*.ppk(例如server.ppk)

#啟動用戶端測試

2).open putty.exe--Category-SSH-Auth-Private key file for authentication #匯入ppk檔案

#輸入之前在server上設定的passphrase登入

3).login as: smallfish

Authenticating with public key "imported-openssh-key"

Passphrase for key "imported-openssh-key":

Ok, 配置完成。

問題:

1.用戶端用key登陸的時候提示:

Disconnected: No supported authentication methods available

解決:是由於在用戶端puttygen產生ppk檔案的時候重新用了Generate命令,直接匯入id_dsa檔案然後save private key即可。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.