远程管理服务器 免密登录 3(运维笔记)

远程管理服务器 免密登录 3(运维笔记)

任务开发人员通过远程业务用户pos登录服务器实现免密登录

server1新建pos用户,设置密码:

[root@server1 ~]# useradd pos
[root@server1 ~]# passwd pos
更改用户 pos 的密码 。
新的 密码:
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。

另一主机server2的code用户远程登录

首先在server2主机的code用户生成一对密钥:公钥和私钥

[code@server2 ~]$ ls -a  #登录code账号 查看文件
.  ..  .bash_logout  .bash_profile  .bashrc  .ssh


[code@server2 ~]$ cd .ssh/  #进入目录
[code@server2 .ssh]$ ssh-keygen  #生成密钥
Generating public/private rsa key pair.
Enter file in which to save the key (/home/code/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/code/.ssh/id_rsa.
Your public key has been saved in /home/code/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:NvkGn64Fi/PIsHihBAkVyM3BeiNY4xmxjHtxVrE/3gI code@server2
The key's randomart image is:
+---[RSA 2048]----+
|.oB+. o.         |
|o++= . .         |
|++=+o .          |
|++o*   . .       |
|.++ . E S        |
| .. .  = X .     |
| . ...o + B      |
|  ...+ + =       |
|  ... o o..      |
+----[SHA256]-----+
[code@server2 .ssh]$ ll
total 12
-rw------- 1 code code 1679 Apr 14 10:16 id_rsa
-rw-r--r-- 1 code code  394 Apr 14 10:16 id_rsa.pub
-rw-r--r-- 1 code code  171 Apr 14 10:12 known_hosts


把code用户公钥拷贝到远程主机上server1的pos用户的家目录里(~/.ssh/xxx)

[code@server2 .ssh]$ ssh-copy-id -i pos@121.199.54.222 #你需要远程免密登录的主机和用户
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/code/.ssh/id_rsa.pub"
The authenticity of host '121.199.54.222 (121.199.54.222)' can't be established.
ECDSA key fingerprint is SHA256:NTa2GLaVBM+N/T9canF+dKw2gF6Lee2UbntGFgGieZE.
ECDSA key fingerprint is MD5:9e:8b:f1:90:d1:8a:70:2f:44:54:f5:fa:7d:df:1f:39.
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
pos@121.199.54.222's password: 

Number of key(s) added: 1

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


在server1的pos用户上.ssh/查看:

[pos@server1 ~]$ cd .ssh/
[pos@server1 .ssh]$ ll
total 4
-rw------- 1 pos pos 394 Apr 14 10:21 authorized_keys

生成认证钥匙

测试验证

[code@server2 .ssh]$ ssh pos@121.199.54.222
Last login: Fri Apr 14 10:19:48 2023

Welcome to Alibaba Cloud Elastic Compute Service !

[pos@server1 ~]$ 

使用pos用户远程实现免密登录

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值