1. 程式人生 > >ssh 免登陸配置

ssh 免登陸配置

在配置Hadoop叢集分佈時,要使用SSH免密碼登入,假設現在有兩臺機器[email protected](192.168.10.100),作為A機,[email protected](192.168.10.107),作為B機。現想[email protected]通過ssh免密碼登入到[email protected]

1.在A機下生成公鑰/私鑰對。
[[email protected] ~]$ ssh-keygen -t rsa -P
''
   敲擊回車鍵即可,
   它在/home/hadoop下生成.ssh目錄,.ssh下有id_rsa和id_rsa.pub。
2.把A機器下的id_rsa.pub複製到B機器下的.ssh/authorized_keys檔案裡。
[[email protected]
~]$ scp .ssh/id_rsa.pub [email protected]:/home/hadoop/id_rsa.pub.hadoop_wang
[email protected]'s password:

   由於還沒有免密碼登入的,所以要輸入密碼。


3.B機把從A機複製的id_rsa.pub.hadoop_wang新增到.ssh/authorzied_keys檔案裡。
[
[email protected]
~]$ cat id_rsa.pub.hadoop_wang >> .ssh/authorized_keys
[[email protected] ~]$ chmod 600 .ssh/authorized_keys

   authorized_keys的許可權要是600。


4.A機登入B機。
[[email protected] ~]$ ssh 192.168.10.107
   第一次登入是時要你輸入yes。
   現在A機可以無密碼登入B機了。

小結:登入的機子可有私鑰,被登入的機子要有登入機子的公鑰。這個公鑰/私鑰對一般在私鑰宿主機產生。上面是用rsa演算法的公鑰/私鑰對,當然也可以用dsa(對應的檔案是id_dsa,id_dsa.pub)
想讓A,B機無密碼互登入,那B機以上面同樣的方式配置即可,把B的公鑰複製過去新增到authorized_keys的末尾就行了。