Linux SSH快速实现免密登录

创建密钥

ssh-keygen -t ecdsa -b 521

一路回车即可

[root@bxy1 ~]# ssh-keygen -t ecdsa -b 521
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:1uCEuKpBzpAxbXCyWfK4Ph2MJJ/7SZ/EukwIljXu208 root@bxy1
The key's randomart image is:
+---[ECDSA 521]---+
|+ o              |
| %   . .         |
|B.+o. . o        |
|oB*... o o       |
|==o+.   S .      |
|B.o+.. .         |
|.=+oo oE         |
| o.=o=..         |
|.  .*o+.         |
+----[SHA256]-----+

Copy公钥

ssh-copy-id -i ~/.ssh/id_ecdsa.pub root@<对端IP>

登录对比

未配置

[root@bxy1 ~]# ssh ssh.liumou.site
The authenticity of host 'ssh.liumou.site (106.55.188.168)' can't be established.
ECDSA key fingerprint is SHA256:IrcW68jVTFdtgFJ6alwyatONbWYg+rkdlhKmB7VRxjI.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'ssh.liumou.site,106.55.188.168' (ECDSA) to the list of known hosts.
root@ssh.liumou.site's password: 
Linux l 4.19.0-11-amd64 #1 SMP Debian 4.19.146-1 (2020-09-17) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat Mar 26 23:52:21 2022 from 116.252.46.164
root@l:~# logout
Connection to ssh.liumou.site closed.

开始配置

[root@bxy1 ~]# ssh-copy-id -i ~/.ssh/id_ecdsa.pub root@ssh.liumou.site
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_ecdsa.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@ssh.liumou.site's password: 

Number of key(s) added: 1

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

免密验证

[root@bxy1 ~]# ssh ssh.liumou.site
Linux l 4.19.0-11-amd64 #1 SMP Debian 4.19.146-1 (2020-09-17) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat Mar 26 23:55:57 2022 from 202.103.199.196
root@l:~# 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

坐公交也用券

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

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

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

打赏作者

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

抵扣说明:

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

余额充值