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