Ubuntu免密ssh登录
1设置root密码
Ubuntu初始没有root密码,需要预先设置,不然在之后会报错。
sudo passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
2设置映射
vim /etc/hosts
127.0.0.1 localhost
192.168.1.2 master
192.168.1.3 node1
#各主机之间映射表应相同
#可通过scp 复制
#可以不弄,可以直接输ip
3生成公钥
ssh-keygen
#输入ssh-keygen之后出现有选择保存目录、描述等,可直接默认
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:
之后/root/.ssh目录会增加文件id_rsa 、id_rsa.pub
4保存公钥
#node1
scp id_rsa.pub root@[ip]:/root/.ssh/id1
#master
cat id1 >>authorized_keys
cat id_rsa.pub >>authorized_keys
scp authorized_keys root@[ip]:roo/.ssh/authorized_keys
#保存的映射用于登录其他电脑是可以替代,不必输入ip地址
至此,结束。
5附加、简单粗暴法
ssh-copy-id master
#ssh-copy-id 把对方的公钥保存到自己的authorized_keys文件,
#重复执行到每一个机子,再复制可以相当于3.4步(个人觉得)