Linux下SSH免密码登录(转)

时间:2024-09-07 23:36:32

搭建hadoop集群的时候一定会用到的就是SSH免密码登录

[hadoop@hadoop1 ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hadoop/.ssh/id_rsa):
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:
::da:::3d::::bf:eb::d1::d9: hadoop@hadoop1
The key's randomart image is:
+--[ RSA ]----+
| ..+ + |
| o . o E . |
| o . + |
| o . .o . |
| o o + S o |
| . . * + .. |
| o o .. |
| .. |
| .. |
+-----------------+
[hadoop@hadoop1 ~]$ cd .ssh
[hadoop@hadoop1 .ssh]$ scp -r id_rsa.pub hadoop@hadoop3:/home/hadoop/.ssh/authorized_keys
The authenticity of host 'hadoop3 (192.168.127.120)' can't be established.
RSA key fingerprint is :be:af::::6d::7e:dd::fa::b3::2f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'hadoop3,192.168.127.120' (RSA) to the list of known hosts.
hadoop@hadoop3's password:
id_rsa.pub % .4KB/s :
[hadoop@hadoop1 .ssh]$ ssh hadoop3
Last login: Sat Aug :: from hadoop1

如果不能没有成功

方法一:

[hadoop@hadoop3 ~]$ chmod  .ssh/
[hadoop@hadoop3 ~]$ cd .ssh
[hadoop@hadoop3 .ssh]$ chmod authorized_keys

方法二:

[root@hadoop3 .ssh]# vi /etc/ssh/sshd_config
AuthorizedKeysFile .ssh/authorized_keys 把前面的#号去掉
[root@hadoop3 .ssh]# /etc/rc.d/init.d/sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]