Linux客户端免密登录服务端

要求:在客户端xiaobo免密登录上服务端root用户

首先创建客户端xiaobo

[root@localhost ~]# useradd xiaobo
[root@localhost ~]# passwd xiaobo 
更改用户 xiaobo 的密码 。
新的密码: 
无效的密码: 密码少于 8 个字符
重新输入新的密码: 
passwd:所有的身份验证令牌已经成功更新。

然后在客户端创建自己的公私秘钥

[xiaobo@localhost root]$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/xiaobo/.ssh/id_rsa):   #/home/xiaobo/.ssh/id_rsa为公,私秘钥的文件位置
Created directory '/home/xiaobo/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/xiaobo/.ssh/id_rsa
Your public key has been saved in /home/xiaobo/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:SARzbaApQhJRfQIzZQpVuhnPpVY1xxFPLS2XTCltPtk xiaobo@localhost.localdomain
The key's randomart image is:
+---[RSA 3072]----+
|=**=*.+oo.+o.*.o |
|o. *o*..oo.o+ X  |
|. = oo+.    .B o |
| . B = .      + E|
|  o = . S      . |
|   .             |
|                 |
|                 |
|                 |
+----[SHA256]-----+

查看秘钥是否创建成功

[xiaobo@localhost root]$ ll /home/xiaobo/.ssh/
总用量 8
-rw-------. 1 xiaobo xiaobo 2622  3月 11 13:06 id_rsa
-rw-r--r--. 1 xiaobo xiaobo  582  3月 11 13:06 id_rsa.pub  #.pub 的文件为公有秘钥

再将客户端的公有秘钥发送给服务端

[xiaobo@localhost root]$ ssh-copy-id root@192.168.181.128
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/xiaobo/.ssh/id_rsa.pub"
The authenticity of host '192.168.181.128 (192.168.181.128)' can't be established.
ED25519 key fingerprint is SHA256:7H0jMo7MTdDaQHkKQwdx2A8lLzRvyqpo1Ui8MPbhW34.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? 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@192.168.181.128's password:   #输入客户端root用户密码

Number of key(s) added: 1

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

服务端收到秘钥后就可以进行远程免密登录

[xiaobo@localhost root]$ ssh root@192.168.181.128
Activate the web console with: systemctl enable --now cockpit.socket

Register this system with Red Hat Insights: insights-client --register
Create an account or view all your systems at https://red.ht/insights-dashboard
Last login: Sat Mar 11 11:47:30 2023 from 192.168.181.1

最后结果

[root@localhost ~]# ip a
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: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:0b:8a:5d brd ff:ff:ff:ff:ff:ff
    altname enp3s0
    inet 192.168.181.128/24 brd 192.168.181.255 scope global dynamic noprefixroute ens160
       valid_lft 1681sec preferred_lft 1681sec
    inet6 fe80::20c:29ff:fe0b:8a5d/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

North433

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

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

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

打赏作者

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

抵扣说明:

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

余额充值