Linux: ssh免密登陆
配置 ssh 免密码登陆,在这里先实现免密码登陆本机
生成公钥
执行这个命令以后,需要连续按 4 次回车键,回到 linux 命令行,才表示这个操作执行结束。在按回车的时候不需要输入任何内容。
[root@hadoop100 ~]# 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:
20:d0:89:24:29:1e:c8:50:b3:fb:e0:57:76:94:0c:ea root@hadoop100
The key's randomart image is:
+--[ RSA 2048]----+
|*+=o .. |
|++.+o. o . |
|o o o . + |
| . o . o |
| o E o S |
| . o o . |
| . o |
| . |
| |
+-----------------+
向被访问主机复制公钥
[root@hadoop100 ~]# cat ~/.ssh/id_*.pub | ssh root@10.20.1.188 'cat >> .ssh/authorized_keys'
修改hosts
[root@hadoop100 ~]# vi /etc/hosts
10.20.1.188 hadoop01
验证
执行 ssh 命令验证免密码登陆是否配置成功,第一次验证的时候会提示输入 yes 或 no,直接输入 yes 即可,如果输入了 yes 之后按回车可以进入就表示免密码登陆配置成功。
[root@hadoop100 ~]# ssh hadoop01
Last login: Tue Aug 18 17:41:27 2020 from 10.200.2.120
[root@hadoop01 ~]#