linux(ubuntu)2臺互相ssh無密碼訪問

最佳方式:

1. sudo apt-get update

2. 安裝ssh

sudo apt-get install openssh-server

3. 生成公鑰

ssh-keygen  -t rsa

以上3步驟AB機器均需要實現(已完成12步驟的可以只進行3)

在主機A上實現:

4. cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

5. ssh 192.168.1.148 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

6. scp ~/.ssh/authorized_keys 192.168.1.148:~/.ssh/authorized_keys

7. 修改文件權限

 cd ~/.ssh

sudo chmod 755 .ssh 以及 sudo chmod 644 authorized_keys

8. ssh-add

這樣A便能ssh無密碼訪問B,其中192.168.1.148爲主機B的ip地址

若要實現Bssh無密碼訪問A,則需要在主機B上執行4-8步驟


實際場景(採用鏈接1):

hadoop@Slave1-hadoop:~$ sudo service ssh start

[sudo] password for hadoop:
start: Job is already running: ssh
hadoop@Slave1-hadoop:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hadoop/.ssh/id_rsa):
Created directory '/home/hadoop/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/hadoop/.ssh/id_rsa.
Your public key has been saved in /home/hadoop/.ssh/id_rsa.pub.
The key fingerprint is:
42:49:47:44:69:f6:b1:13:ae:e5:28:23:5f:f6:74:9b hadoop@Slave1-hadoop
The key's randomart image is:
+--[ RSA 2048]----+
|      .+=.       |
|     . o+ o      |
|      oo o +     |
|     .    *      |
|      . S= .     |
|    . o.= o .    |
|     o = o . o   |
|      .   . E    |
|                 |
+-----------------+
hadoop@Slave1-hadoop:~$ cd .ssh
hadoop@Slave1-hadoop:~/.ssh$ cat id_rsa.pub >> authorized_keys

hadoop@Slave1-hadoop:~/.ssh$ scp id_rsa.pub 166.111.82.38@Slave2-hadoop:/home/hadoop/id_rsa.pub


參考鏈接:

1.http://jingyan.baidu.com/article/3f16e003c918092591c103a2.html

2. http://www.it165.net/os/html/201311/6595.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章