本文中使用的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 22AddressFamily anyListenAddress 0.0.0.0ListenAddress ::#然后开启允许远程登录PermitRootLogin yes#最后,开启使用用户名密码来作为连接验证PasswordAuthentication yes
下面是已修改好的,可以比照参考,可以使用ssh工具链接的的sshd_config配置文件。
Port 22AddressFamily anyListenAddress 0.0.0.0ListenAddress ::HostKey /etc/ssh/ssh_host_rsa_keyHostKey /etc/ssh/ssh_host_ecdsa_keyHostKey /etc/ssh/ssh_host_ed25519_key# Ciphers and keying#RekeyLimit default none# Logging#SyslogFacility AUTH#LogLevel INFO# Authentication:#LoginGraceTime 2mPermitRootLogin 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的登录名和密码。
正确输入用户名和密码后,登陆成功