在Windows中通过SSH工具连接虚拟机中的Linux

在Windows中通过SSH工具连接虚拟机中的Linux

解决方案goocz2025-06-04 16:33:006A+A-

本文中使用的SSH工具是MobaXterm,Linux是深度操作系统(DeepinOS)。

1、查看系统是否安装openssh

dpkg -l | grep openssh-server

此处已经显示笔者系统里安装了,如果没有任何输出显示就表示没有安装,通过命令

sudo apt install openssh-server

2、切换到目录/etc/ssh,使用vim编辑器打开sshd_config配置文件,开启监听端口,监听地址。

主要的几句话需要放开,去掉#号。

sudo vim sshd_config
#将文件中,关于监听端口、监听地址前的 # 号去除
Port 22
AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::

#然后开启允许远程登录
PermitRootLogin yes

#最后,开启使用用户名密码来作为连接验证
PasswordAuthentication yes

下面是已修改好的,可以比照参考,可以使用ssh工具链接的的sshd_config配置文件。

Port 22
AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::

HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
AuthorizedKeysFile	.ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

按Esc键,退出编辑模式,输入 :wq 回车,保存刚才编辑好了的文件。

3、开启sshd 服务,输入 命令

sudo service sshd start

4、检查 sshd 服务是否已经开启,输入命令

ps -e | grep sshd

如果有输出显示说明已经启动。

5、查看Linux的IP

ifconfig

6、在Windows中查看是否能连通Linux

ping 192.168.189.130

7、用MobaXterm连接Linux

出现以下画面说明已经成功连接上虚拟机中的Linux,只需输入用户名和密码,也就是你的Linux的登录名和密码。

正确输入用户名和密码后,登陆成功

点击这里复制本文地址 以上内容由goocz整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!

果子教程网 © All Rights Reserved.  蜀ICP备2024111239号-5