Linux 系统间设置ssh免密登录

本文详细介绍了如何使用ssh-keygen命令生成RSA公钥和私钥,并通过ssh-copy-id命令将公钥复制到目标机器,实现SSH免密登录。步骤包括生成密钥对、设置权限及拷贝公钥,最终成功实现无密码访问。
摘要由CSDN通过智能技术生成

生成公钥和私钥

执行命令:ssh -keygen -t rsa
就会生成两个文件id_rsa(私钥)、id_rsa.pub(公钥)

将公钥拷贝到要免密登录的目标机器上

执行命令:ssh-copy-id hadoop131

效果

[root@localhost ~]# 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:8T6unfKR17oRUgZoroaWhT89ihZQoj7ugsM2IyvryB4 root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
|         ..      |
|  . .   o  .     |
| . o . o.   o    |
|. . . . .o o     |
|.  . = oS o .    |
| o  = = o. o o   |
|+E.. + o .= o .  |
|O*. o . .o = o   |
|%Oo.    .+= o.   |
+----[SHA256]-----+
[root@localhost ~]# ssh-copy-id root@hadoop131
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'hadoop131 (192.168.15.131)' can't be established.
ECDSA key fingerprint is SHA256:FPygJWbfLJ3M5RHZLVRgKmtRhQSpIShAU4m9Wq0C3c0.
ECDSA key fingerprint is MD5:9b:35:f5:de:01:80:f9:e9:e2:70:17:72:29:60:4f:24.
Are you sure you want to continue connecting (yes/no)? 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@hadoop131's password: 

Number of key(s) added: 1

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

[root@localhost ~]# ssh root@hadoop131
Last login: Sun Jul  4 21:27:38 2021 from 192.168.15.1
[root@localhost ~]# ll
总用量 4
-rw-------. 1 root root 1427 5月  16 23:26 anaconda-ks.cfg
drwxr-xr-x. 3 root root   17 5月  16 23:57 install
[root@localhost ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:8d:ae:3b brd ff:ff:ff:ff:ff:ff
    inet 192.168.15.131/24 brd 192.168.15.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::5368:7f7e:f9a4:13f0/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@localhost ~]# exit
登出
Connection to hadoop131 closed.

在视频里学到的记录下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值