配置多台linux免密登陆

2 篇文章 0 订阅

Linux多台SSH免密登陆配置

一、虚拟机环境准备

服务器:192.168.58.71、192.168.58.72、192.168.58.73

二、配置服务器名称和/etc/hosts文件
1、配置192.168.58.71服务器

hostnamectl set-hostname node1

配置/etc/hosts文件

cat > /etc/hosts <<EOF
> 192.168.58.71 node1
> 192.168.58.72 node2
> 192.168.58.73 node3
> EOF

2、配置192.168.58.72服务器

hostnamectl set-hostname node2

配置/etc/hosts文件

cat > /etc/hosts <<EOF
> 192.168.58.71 node1
> 192.168.58.72 node2
> 192.168.58.73 node3
> EOF

3、配置192.168.58.73服务器

hostnamectl set-hostname node3

配置/etc/hosts文件

cat > /etc/hosts <<EOF
> 192.168.58.71 node1
> 192.168.58.72 node2
> 192.168.58.73 node3
> EOF

三、配置SSH免密登陆
1、配置192.168.58.71服务器
生成公私密钥

ssh-keygen -t rsa
[root@localhost ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
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:
SHA256:HRPWxx3i6UGiIY6TCuOw8iy/zKHZ2zzl0cgO0h/5kxI root@node1
The key's randomart image is:
+---[RSA 3072]----+
|       . .oo + o.|
|      + ..o.= = .|
|.o   + . .o  =   |
|o.o . .  . o. .  |
|o. o . +S .  .   |
|.o. o E .        |
|. +. * = .       |
| O +. = +        |
|o Boo. . .       |
+----[SHA256]-----+

查看生成的文件

ll -a

在这里插入图片描述
四,配置自己免登录

1:进入到192.168.58.71的 ssh下面

cd .ssh

把自己当前生成的公钥配置追加到自己的认证文件中。

cat id_rsa.pub >> authorized_keys

修改权限

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

拷贝192.168.58.71服务器公钥到其他两台服务器(拷贝时需要收入root用户登录密码)

ssh-copy-id node2

ssh-copy-id node3

2:进入到192.168.58.72的 ssh下面

cd .ssh

把自己当前生成的公钥配置追加到自己的认证文件中。

cat id_rsa.pub >> authorized_keys

修改权限

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

拷贝192.168.58.71服务器公钥到其他两台服务器(拷贝时需要收入root用户登录密码)

ssh-copy-id node1

ssh-copy-id node3

3:进入到192.168.58.73的 ssh下面

cd .ssh

把自己当前生成的公钥配置追加到自己的认证文件中。

cat id_rsa.pub >> authorized_keys

修改权限

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

拷贝192.168.58.71服务器公钥到其他两台服务器(拷贝时需要收入root用户登录密码)

ssh-copy-id node2

ssh-copy-id node1

五:测试从node1进入到node2

ssh node2
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值