Linux不间断会话服务

9.2.3远程传输命令

家里有2台电脑,一台是ubuntu虚拟机,另一台是rhel8虚拟机器,两台虚拟机都是通过桥接的方式(桥接方式就是虚拟机直接和路由器连接)上网。然后现在用ubuntu来使用sshd服务登录rhel8系统。

用ip addr命令查出unbunt的ip地址:192.168.1.40

用ip addr命令查出rhel8系统的ip地址:192.168.1.80

开始工作之前必须先保证两个机器都开启了sshd服务,首先在ubuntu上执行

复制代码
ps -e | grep ssh

结果知识显示了ssh agent,没有显示sshd,所以根本就没有开启sshd服务,然后自己执行如下命令开启sshd服务,然后提示错误,说是根本没有这个服务,这个时候我意识到自己系统没有安装sshd服务,所以自己安装:

复制代码
systemctl start sshd

然后自己执行如下命令来大胆地安装sshd服务(我的版本是ubuntu20.04):

复制代码
sudo apt install sshd

接着自己可以正确执行下面的命令来开启sshd服务了:

复制代码
systemctl start sshd

说明:网上其他地方说是用 sudo apt install openssh-service,但是我自己这个命令才可以用。

首先,在unbunt上执行如下指令来登录rhel8系统:

一、下面做几个实验,来验证自己的猜想。

客户端机(ubuntu系统,Ip:192.168.1.40),服务端机(rhel8系统,ip 192.168.1.38).

1.尝试通过修改服务器机的文件/etc/ssh/sshd_conf(ip地址是192.168.1.38),具体更改详细如下图红框内所示,然后执行systemctl restart sshd重启sshd服务

然后在另一个客户端机上执行命令登录上一个机器(ip 192.168.1.38),如下:

复制代码
root@ubuntu:/home/r# ssh 192.168.1.38
root@192.168.1.38's password: 
Permission denied, please try again.
root@192.168.1.38's password: 
Permission denied, please try again.
root@192.168.1.38's password: 
root@192.168.1.38: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
root@ubuntu:/home/r# 

结论:在服务端机器上的 /etc/ssh/sshd_config文件中的PermitRootLogin 改为no后,然后客户端机利用root身份就不能登录了。但是如果以普通身份登录,还是可以的,如下:

复制代码
r@ubuntu:~$ ssh 192.168.1.38
r@192.168.1.38's password: 
Activate the web console with: systemctl enable --now cockpit.socket

This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
To register this system, run: insights-client --register

Last login: Wed Oct 18 09:20:09 2023 from 192.168.1.40
[r@localhost ~]$ 

这个实验就验证了/etc/ssh/ssh_config/中的PermitRootLogin选项,如果值是yes,那么客户端机可以以root身份登录,反之,则不可以。

每次更改完毕之后,必须要在本地重启sshd服务才可以生效。

相关推荐
chlk1231 天前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑1 天前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件1 天前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
深紫色的三北六号1 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash2 天前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI2 天前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
十日十行3 天前
Linux和window共享文件夹
linux
木心月转码ing3 天前
WSL+Cpp开发环境配置
linux
崔小汤呀4 天前
最全的docker安装笔记,包含CentOS和Ubuntu
linux·后端
何中应4 天前
vi编辑器使用
linux·后端·操作系统