linux集群ssh免密登录配置

文章目录

  • linux集群ssh免密登录配置
    • 一、准备工作
    • 二、免登陆配置
      • 2.1 设置秘钥
      • 2.2 将秘钥复制到三台服务器上
    • 三、具体操作
    • 四、验证免登陆

linux集群ssh免密登录配置

背景:启动一些集群脚本时,使用ssh远程时都需要登录操作,比较繁琐,配置ssh免密登录,可以提高效率。

一、准备工作

虚拟机准备,默认使用VMware虚拟化了三台机器,且IP地址如下:

192.168.203.101
​192.168.203.102
​192.168.203.103

二、免登陆配置

2.1 设置秘钥

## 第一步:设置秘钥
[root@rentyk ~]# ssh-keygen -t rsa

2.2 将秘钥复制到三台服务器上

## 第二步:将秘钥复制到三台服务器上
[root@rentyk ~]# ssh-copy-id 192.168.203.101
[root@rentyk ~]# ssh-copy-id 192.168.203.102
[root@rentyk ~]# ssh-copy-id 192.168.203.103

每次操作完,输入密码并回车,提示Number of key(s) added: 1,说明添加成功

三、具体操作

操作截图如下:

[root@rentyk ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
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:
SHA256:UCqv3cVwhhoK+m8flawdlepsTYUTTpbOt+EWSzXdRZQ [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|        . +.   +B|
|       o =.+  oEo|
|  . . + ooO .. . |
| . . + = Ooo=    |
|.   . o S ++ =   |
| .   o B =  =    |
|  . . + * ..     |
|   ..  o         |
|   ....          |
+----[SHA256]-----+
[root@rentyk ~]# ssh-copy-id 192.168.203.101
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '192.168.203.101'"
and check to make sure that only the key(s) you wanted were added.

[root@rentyk ~]# ssh-copy-id 192.168.203.102
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '192.168.203.102'"
and check to make sure that only the key(s) you wanted were added.

[root@rentyk ~]# ssh-copy-id 192.168.203.103
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 
Permission denied, please try again.
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '192.168.203.103'"
and check to make sure that only the key(s) you wanted were added.

四、验证免登陆

验证是否成功,使用exit命令进行退出操作

[root@rentyk ~]# ssh 192.168.203.102
Last login: Mon Nov  7 11:33:19 2022 from 192.168.203.101
[root@rentyk ~]# exit
登出
Connection to 192.168.203.102 closed.

你可能感兴趣的:(linux,linux)