linux服务器之间ssh免密码设置

本文详细介绍了如何在Linux环境中使用SSH进行免密登录配置,包括生成公钥、私钥,将公钥复制到目标服务器,并验证配置是否成功。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

应用场景:test01 ssh访问test02,不需要输入密码

 

登录test01

 

第一步:生成公钥、私钥

[root@test01 ~]# ssh-keygen
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:
b8:cf:14:8f:ae:69:2a:fb:ba:1a:60:d8:8a:f8:4c:1a root@test01
[root@test01 ~]#

 

 

第二步:复制公钥到被管理的服务器test02

 

[root@test01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub "root@192.168.1.19"
21
The authenticity of host '192.168.1.19 (192.168.1.19)' can't be established.
RSA key fingerprint is a7:47:b2:f6:e7:ef:8f:2c:9d:9c:03:74:de:3b:e1:55.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.19' (RSA) to the list of known hosts.
root@192.168.1.19's password:
Now try logging into the machine, with "ssh 'root@192.168.1.19'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

[root@test01 ~]#

 

最后就可以直接 ssh root@192.168.1.19 登录test02,而不用再输入密码

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值