远程服务连接

一.配置两台主机
主机1.
主机名: server.example.com
ip: 172.25.254.100
建立用户timinglee,其密码为timinglee

[root@server100 ~]# hostnamectl hostname server.example.com
[root@server100 ~]# hostname
server.example.com

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


主机2
主机名:client.example.com
ip: 172.25.254.200

[root@server200 ~]# hostnamectl hostname client.example.com
[root@server200 ~]# hostname
client.example.com


2.安需求完成项目
172.25.254.200 在远程登录172.25.254.100的root用户时需要免密连接
并确保只有root用户和timinglee用户可以被登录

首先在俩台虚拟机上输入systemctl restart sshd命令,启用sshd服务才可以相互连接

然后在主机二中

[root@server200 ~]#  ssh-keygen -f /root/.ssh/id_rsa -P ""
Generating public/private rsa key pair.
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:5UBDZ+KDEbIi3Ec+qmWAHlVVXx+3upH0SHqJg3POG4k root@client.example.com
The key's randomart image is:
+---[RSA 3072]----+
|   .oo++*.o  . ..|
|o o oo = =. . . +|
|o+...+. + .. o o |
|..o.o .  =. = *  |
| . +    So.= B . |
|  +       * + o  |
| .       E = .   |
|            o    |
|           .     |
+----[SHA256]-----+
 

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

Number of key(s) added: 1

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

随后在主机一中

[root@server ~]# vim /etc/ssh/sshd_config

[root@server ~]# systemctl restart sshd
然后重启sshd服务,任务完成

验证一下

[root@server200 ~]# ssh -l root 172.25.254.100
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: Sun Apr 21 14:46:38 2024 from 172.25.254.200
实现root免密登录

[root@server100 ~]# ssh -l timinglee 172.25.254.100
timinglee@172.25.254.100's password: 
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 failed login: Sun Apr 21 15:07:35 CST 2024 from 172.25.254.100 on ssh:notty
There was 1 failed login attempt since the last successful login.
Last login: Sun Apr 21 14:47:23 2024 from 172.25.254.100
实现timinglee登录

[root@server200 ~]# ssh -l joker 172.25.254.100
joker@172.25.254.100's password: 
Permission denied, please try again.
joker@172.25.254.100's password: 
Permission denied, please try again.
joker@172.25.254.100's password: 
joker@172.25.254.100: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
登录joker账户被拒绝

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值