linux利用ssh实现免密登录

免密登录

1.生成密钥

#返回当前用户
cd
#生成密钥
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:8Ar9Nslis+Iy9lL0VY9R7YNOIprTFZasXj5yooEpl5g root@single01
The key's randomart image is:
+---[RSA 2048]----+
|         . o..   |
|          B   .  |
|      .  + = o   |
|    .. o+ = + o  |
|   +.=.*S= +   . |
|  E *.*+=.+ .    |
|   +  =+*+ .     |
|  = ...= .       |
| . *o..          |
+----[SHA256]-----+
#------------------------------------------------------------------

2.查看密钥

#列出文件
ls -la
#--------------------------------------------------------
total 24
dr-xr-x---.  4 root root  138 Dec 20 14:14 .
dr-xr-xr-x. 17 root root  224 Dec 20 09:13 ..
-rw-------.  1 root root 1403 Dec 20 09:14 anaconda-ks.cfg
-rw-r--r--.  1 root root   18 Dec 29  2013 .bash_logout
-rw-r--r--.  1 root root  176 Dec 29  2013 .bash_profile
-rw-r--r--.  1 root root  176 Dec 29  2013 .bashrc
-rw-r--r--.  1 root root  100 Dec 29  2013 .cshrc
drwxr-----.  3 root root   19 Dec 20 12:05 .pki
drwx------.  2 root root   38 Dec 20 14:14 .ssh
-rw-r--r--.  1 root root  129 Dec 29  2013 .tcshrc
#---------------------------------------------------------
ls .ssh/
#-----------------
id_rsa  id_rsa.pub
#-----------------

3.本机免密

cat ./ssh/id_rsa.pub >> .ssh/authorized_keys

4.查看是否免密成功

ls .ssh
#----------------------------------
authorized_keys  id_rsa  id_rsa.pub
#----------------------------------

5.连接主机

ssh root@single01
#----------------------------------------------------------------------------------------
The authenticity of host 'single01 (192.168.50.102)' can't be established.
ECDSA key fingerprint is SHA256:bInNUWaomyIdiZEbrXk00HZsCEQrgBTP0+RfD5RyQ/g.
ECDSA key fingerprint is MD5:9f:95:6c:5b:38:1f:a7:14:80:a6:96:21:19:cb:3e:37.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'single01,192.168.50.102' (ECDSA) to the list of known hosts
ssh root@single01
root@single01's password: 
Last login: Mon Dec 20 10:41:44 2021 from 192.168.50.1
#----------------------------------------------------------------------------------------

6.查看是否连接成功

ls .ssh/
#-----------------------------------------------
authorized_keys  id_rsa  id_rsa.pub  known_hosts
#-----------------------------------------------
cat .ssh/known_hosts 
#----------------------------------------------------------------------------------------
single01,192.168.50.102 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBA6Wf3eKai79AwEKYBomG4ZbN1fIio9TjW0xf8l0cfwDPoNYGOWyt2MyhafZqatRBBvYq4QcjgfV/3sNLOabimk=
#----------------------------------------------------------------------------------------
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

绝域时空

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

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

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

打赏作者

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

抵扣说明:

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

余额充值