多个服务器之间免密登录

多个服务器之间免密登录

免密登录流程

A服务器 B服务器 生产密钥对 拷贝公钥 SSH访问B(数据用私钥A加密) 去授权key中查找A的公钥并解密数据 采用A公钥加密数据返回A 用A的私钥解密数据 A服务器 B服务器

操作流程

生成公钥和私钥

使用ssh-keygen -t rsa生成秘钥

输出结果

使用命令会让你设置保存地址和私钥密码这里需要直接回车使用默认和空密码

[root@localhost102 data]# 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:sq************************************tDm root@localhost102
The key's randomart image is:
***************************************************
拷贝密钥

直接使用ssh-copy-id拷贝秘钥

输出结果

[root@localhost102 data]# ssh-copy-id localhost103
/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
root@localhost103's password: 

Number of key(s) added: 1

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

使用ssh登录其他服务器

这样就可以使用ssh免密登录其他服务器了

[root@test102 ~]# ssh test103
Last login: Fri Sep 16 08:16:23 2022 from 192.168.65.60
[root@localhost103 ~]# 

.ssh文件夹内容

shh包含以下文件

[root@test102 ~]# ll .ssh/
总用量 16
-rw-------. 1 root root  798 915 15:53 authorized_keys
-rw-------. 1 root root 1679 915 15:25 id_rsa
-rw-r--r--. 1 root root  399 915 15:25 id_rsa.pub
-rw-r--r--. 1 root root  736 915 15:51 known_hosts

文件名说明
id_rsa生成的私钥
id_rsa.pub生成的公钥
authorized_keys存放授权过的无密登录服务器公钥
known_hosts记录ssh访问过计算机的公钥(public key)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大·风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值