您的位置:首页 > 其它

Ubuntu群免密ssh登录

2020-02-03 04:36 113 查看

Ubuntu免密ssh登录

ssh-copy-id设置root密码设置映射表生成公钥保存公钥完成

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步(个人觉得)
  • 点赞
  • 收藏
  • 分享
  • 文章举报
Lnu_lizi 发布了5 篇原创文章 · 获赞 0 · 访问量 57 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: