ssh無密碼登陸伺服器

來源:互聯網
上載者:User

網上該類教程很多,但還是記錄下,方便以後查詢的時候使用。

兩台伺服器,內網ip分別是:

172.16.3.91 (本地機)

172.16.3.92 (遠程機)

現在想在本地機上通過ssh 172.16.3.92登陸到遠程機而不要求輸入密碼。

1.在本地機上用ssh-keygen 建立公開金鑰私密金鑰。

[root@rs-1 ~]# ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

dc:fc:ea:b8:bb:74:d7:75:4b:6a:27:82:28:27:be:d6 root@rs-1

這個過程會提示輸入密碼,記住直接按斷行符號就行,不要輸入密碼!要是輸入了密碼,一會訪問的時候就需要輸入密碼了。

建立之後能看到如下兩個檔案

[root@rs-1 .ssh]# ll

total 24

-rw------- 1 root root 1675 May 8 07:18 id_rsa

-rw-r--r-- 1 root root 391 May 8 07:18 id_rsa.pub

id_rsa是私密金鑰

id_rsa.pub是公開金鑰, 主要給遠程機使用的

2.把公開金鑰傳到遠程機上去。

[root@rs-1 .ssh]# scp id_rsa.pub root@172.16.3.92:~/.ssh/authorized_keys

Address 172.16.3.92 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!

root@172.16.3.92's password:

id_rsa.pub 100% 391 0.4KB/s 00:00

3.ssh連結時候就不要求輸入密碼了,直接登陸到遠程機

[root@rs-1 .ssh]# ssh 172.16.3.92

Address 172.16.3.92 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!

Last login: Thu May 8 07:19:28 2014 from 172.16.3.91

[root@rs-2 ~]#

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.