三台linux虚拟机免密登录
三台虚拟机免密登录
1.准备好三台虚拟机环境
2.修改对应的主机名
如果没有密钥生成密钥,如果有就不用再次生成,查看密钥命令
ls -la
生成密钥
ssh-keygen -t rsa
生成内容
在第一台机器上设置主机名和ip地址
vim /etc/hosts
在末尾加上以下内容
192.168.242.128 hadoop01 192.168.242.129 hadoop02 192.168.242.130 hadoop03
保存退出。
将hosts文件发送到其他两台虚拟机上
scp /etc/hosts root@192.168.242.129:/etc/
scp /etc/hosts root@192.168.242.130:/etc/
3.拷贝id
将第一台的id拷贝到其他两台
ssh-copy-id hadoop02
ssh-copy-id hadoop03
加入出现一下情况,在hadoop03中执行生成密钥命令即可
/usr/bin/ssh-copy-id: ERROR: failed to open ID file /root/.pub: 没有那个文件或目录 (to install the contents of /root/.pub anyway, look at the -f option) [root@localhost ~]# ssh-copy-id hadoop03 /usr/bin/ssh-copy-id: ERROR: failed to open ID file /root/.pub: 没有那个文件或目录 (to install the contents of /root/.pub anyway, look at the -f option)
4.在第二,第三台虚拟机上重复步骤3即可。
下一篇:
Linux备份文件——shell脚本