ssh机器之间无密码通信
文献:
转载:http://blog.itpub.net/30089851/viewspace-2127102/
转载:http://blog.itpub.net/30089851/viewspace-1992210/
[hadoop@hadoop001 ~]$ which ssh-keygen
/usr/bin/ssh-keygen
[hadoop@hadoop001 ~]$ ll /usr/bin/ssh*
-rwxr-xr-x 1 root root 450728 Sep 1 2017 /usr/bin/ssh
-rwxr-xr-x 1 root root 158920 Sep 1 2017 /usr/bin/ssh-add
-rwxr-sr-x 1 root nobody 141384 Sep 1 2017 /usr/bin/ssh-agent
-rwxr-xr-x 1 root root 1425 Sep 1 2017 /usr/bin/ssh-copy-id
-rwxr-xr-x 1 root root 199880 Sep 1 2017 /usr/bin/ssh-keygen
-rwxr-xr-x 1 root root 253752 Sep 1 2017 /usr/bin/ssh-keyscan
[hadoop@hadoop001 ~]$ ssh-keygen 三次回车
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:
0b:64:be:3c:54:d7:9c:56:b3:5f:8d:93:4a:d6:44:1e hadoop@hadoop001
The key's randomart image is:
+--[ RSA 2048]----+
| .E |
| o * *.|
| o . . B B o|
| + . . + . o.|
| + S . .|
| o o . |
| + . |
| . |
| |
+-----------------+
[hadoop@hadoop001 ~]$ cd .ssh
[hadoop@hadoop001 .ssh]$ ll
total 8
-rw------- 1 hadoop hadoop 1675 Jul 9 01:49 id_rsa 私钥
-rw-r--r-- 1 hadoop hadoop 398 Jul 9 01:49 id_rsa.pub你 公钥
[hadoop@hadoop001 .ssh]$ cat id_rsa.pub 真正需要的是公钥
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2KCZBYaMiDxuIy9S0XwGiu4X2HLSCOy28ph0BcOSS52VyumTrG5zr0LmUZL3spv3O9rkz9KqAOWtYBHL+nYMPOU8wDmbrC4PdrMNo56Wkdt1IyOQBGX1xk7hBQPBXBiTvO3umLB6iLtmIfxM1fixjHirq3k0B9rLyh+GVcgUPGq24hQagep8W7YUlDvTtSReal5ymhJ0zlpx1xeH/Aeq++aI4KLkpU3QR9ju6awgWhWeE9KGluK1e0oYm2Jx6O3JOUc2vXEUI7IIpOp2pLeZwrdH6inS1znE57ukXeQhqy9ijiXbwrC9nosLJEHmQJi25vwZHyuV9KmBx5U/Ghsg0Q== hadoop@hadoop001
用户@机器
[hadoop@hadoop001 .ssh]$ ssh localhost date
The authenticity of host 'localhost (127.0.0.1)' can't be established.
RSA key fingerprint is d4:0e:26:f5:f6:2c:12:17:ba:9d:19:c4:10:fe:d8:2a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (RSA) to the list of known hosts.
hadoop@localhost's password:
Permission denied, please try again.
hadoop@localhost's password:
Permission denied, please try again.
hadoop@localhost's password:
Permission denied (publickey,password).
[hadoop@hadoop001 .ssh]$ ll
total 16
-rw-rw-r-- 1 hadoop hadoop 398 Jul 9 02:05 authorized_keys
-rw------- 1 hadoop hadoop 1675 Jul 9 01:49 id_rsa
-rw-r--r-- 1 hadoop hadoop 398 Jul 9 01:49 id_rsa.pub
-rw-r--r-- 1 hadoop hadoop 391 Jul 9 02:07 known_hosts 还是不行,因为我们配置的是Hadoop001,不是localhost
[hadoop@hadoop001 .ssh]$
[hadoop@hadoop001 .ssh]$ ssh hadoop date
ssh: Could not resolve hostname hadoop: Name or service not known
[hadoop@hadoop001 .ssh]$ ssh hadoop001 data
The authenticity of host 'hadoop001 (106.75.103.178)' can't be established.
RSA key fingerprint is d4:0e:26:f5:f6:2c:12:17:ba:9d:19:c4:10:fe:d8:2a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'hadoop001,106.75.103.178' (RSA) to the list of known hosts.
hadoop@hadoop001's password:
Permission denied, please try again.
hadoop@hadoop001's password:
Permission denied, please try again.
hadoop@hadoop001's password:
Permission denied (publickey,password). Hadoop001还是不行,权限问题,apache官网有关于此处解决方法,cdh无
chmod 700 -R ~/.ssh
chmod 600 ~/.ssh/authorized_keys
[hadoop@hadoop001 .ssh]$ pwd
/home/hadoop/.ssh
[hadoop@hadoop001 .ssh]$ chmod 600 /home/hadoop/.ssh/authorized_keys 按照官网配置600权限
[hadoop@hadoop001 .ssh]$ ll
total 16
-rw------- 1 hadoop hadoop 398 Jul 9 02:05 authorized_keys
-rw------- 1 hadoop hadoop 1675 Jul 9 01:49 id_rsa
-rw-r--r-- 1 hadoop hadoop 398 Jul 9 01:49 id_rsa.pub
-rw-r--r-- 1 hadoop hadoop 797 Jul 9 02:11 known_hosts
[hadoop@hadoop001 .ssh]$ ssh localhost date 成功后测试
Tue Jul 9 02:15:20 CST 2019
[hadoop@hadoop001 .ssh]$ ssh 10.9.6.136 date sh登录localhost机器执行date命令 返回结果 不会做机器切换
Tue Jul 9 02:18:54 CST 2019
[hadoop@hadoop001 .ssh]$ ssh hadoop001 date
Tue Jul 9 02:19:56 CST 2019
[hadoop@hadoop001 .ssh]$ ssh hadoop001 shh登录Hadoop001机器作了机器切换
远程连接
ssh root@ip
输入密码
ssh root@ip date 不会远程切换到ip
a机器想要无秘访问b机器,就要把自己的公钥存放在b机器