Linux服务器之间配置免密通道 只需三步 光速配置~

准备2台linux机器(两台虚拟机,能够ping通)

一.在 client 机器上创建密钥对

有提示的话 不用输入任何文字 直接回车

[root@sc-mysql ~]# ssh-keygen -t ecdsa
Generating public/private ecdsa key pair.
Enter file in which to save the key (/root/.ssh/id_ecdsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_ecdsa.
Your public key has been saved in /root/.ssh/id_ecdsa.pub.
The key fingerprint is:
SHA256:eviPHWDw0JVOQ2GAcZZ4vNw2hg8/EYZiNGSkbEbqxgo root@sc-mysql
The key's randomart image is:
+---[ECDSA 256]---+
|    .+B=+==o     |
|   + o===o*      |
|  . =.o+.B o     |
| o o   += B      |
|E +     S* o     |
|.o     + .+      |
|.     o . ..     |
|       o o .     |
|        o.o      |
+----[SHA256]-----+

可以查看一下公钥和私钥:

[root@sc-mysql ~]# cd /root/.ssh/
[root@sc-mysql .ssh]# ls
id_ecdsa  id_ecdsa.pub  id_rsa  id_rsa.pub  known_hosts
[root@sc-mysql .ssh]# ll
总用量 20
-rw------- 1 root root  227 2月  26 15:02 id_ecdsa
-rw-r--r-- 1 root root  175 2月  26 15:02 id_ecdsa.pub
-rw------- 1 root root 1675 9月  19 22:00 id_rsa
-rw-r--r-- 1 root root  395 9月  19 22:00 id_rsa.pub
-rw-r--r-- 1 root root  876 2月  25 13:31 known_hosts

注意:私钥 id_ecdsa 的权限非常严格,不要修改

二.上传公钥至服务器的root用户的家目录下的.ssh/authorized_keys

ssh-copy-id 用来上传公钥 -i 指定公钥的位置
[root@xyy .ssh]# ssh-copy-id -i id_ecdsa.pub root@192.168.31.26
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "id_ecdsa.pub"
The authenticity of host '192.168.31.26 (192.168.31.26)' can't be established.
ECDSA key fingerprint is SHA256:v7VzMC5tU2w7NRsf9uLJ5jDFZOtONbNFZAL0KInJLXw.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/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@192.168.31.26's password: (192.168.31.26的密码)

Number of key(s) added: 1

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

三.验证免密通道是否成功

ssh是linux下的客户端连接命令

[root@xyy .ssh]# ssh root@192.168.31.26
Last login: Sat Jun 26 11:02:54 2021 from 192.168.31.5
[root@fuwuqi ~]# 

配置成功



感谢各位看官!!!

在这里插入图片描述

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值