公钥私钥实现免登陆

本文介绍了如何生成并配置SSH公钥私钥,以实现在Linux系统间免密码登录。首先通过ssh-keygen命令创建公钥私钥对,然后将公钥传输到目标服务器,最后测试无密码登录是否成功。该方法提高了服务器管理的安全性和效率。
摘要由CSDN通过智能技术生成

设置公钥私钥实现免登陆


一、设置公钥私钥。

1.生成公钥私钥

[root@7-11 ~]# 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:cLF/ydC8mLd4nblBcAz4TLAaqu+LPPhIUrX72b/y8Xs root@7-11
The key's randomart image is:
+---[RSA 2048]----+
|        . .o.    |
|         o.+.o   |
|    . . + o++ o  |
|   . . + + =o=   |
|  . . . S + * .  |
| .   o     + + o |
|. ..o     o o =  |
| o.o.+ o.  +  Eo |
|  ..+o*..++.oo.  |
+----[SHA256]-----+

2.查看生成的公私钥

[root@7-11 ~]# cd /root/.ssh/
[root@7-11 .ssh]# ls
id_rsa  id_rsa.pub

3.把公钥传给服务器2

[root@7-11 ~]# ssh-copy-id root@192.168.100.12
/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@192.168.100.12's password:     # 服务器2的密码

Number of key(s) added: 1

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

4.测试免等是否成功

[root@7-11 ~]# ssh root@192.168.100.12
Last login: Sun May 23 15:57:11 2021 from 192.168.100.253
[root@7-12 ~]# 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值