Linux 能 ping 通,但是 ssh 登陆不上 | 您所在的位置:网站首页 › 云虚拟主机远程连接不上 › Linux 能 ping 通,但是 ssh 登陆不上 |
问题描述
刚刚在本地装了ubuntu虚拟机,发现本地本机能ping通虚拟机网络 $ ping 172.16.0.4 PING 172.16.0.4 (172.16.0.4): 56 data bytes 64 bytes from 172.16.0.4: icmp_seq=0 ttl=64 time=0.385 ms 64 bytes from 172.16.0.4: icmp_seq=1 ttl=64 time=0.775 ms 64 bytes from 172.16.0.4: icmp_seq=2 ttl=64 time=0.697 ms172.16.0.4为ubuntu虚拟机ip,接着使用ssh命令尝试登录服务器 $ ssh [email protected] ssh: connect to host 172.16.0.4 port 22: Connection refused 问题分析本地能ping通虚拟机,证明虚拟机与本机之间的网络连接没问题。那么就有可能是ssh服务的问题,在虚拟机中使用telnet尝试连接22端口 $ telnet 127.0.0.1 22 Trying 127.0.0.1... telnet: Unable to connect to remote host: Connection refused发现22端口连接不上,此时有可能是ssh服务未启动,查看ssh服务状态 $ systemctl status sshd ● sshd.service Loaded: not-found (Reason: No such file or directory) Active: inactive (dead)No such file or directory 表示没安装该服务 问题解决安装ssh服务 $ sudo apt-get install openssh-server安装完openssh-server,再次查看sshd服务状态 $ systemctl status sshd ● ssh.service - OpenBSD Secure Shell server Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2021-02-20 04:07:24 PST; 17min ago Main PID: 6437 (sshd) CGroup: /system.slice/ssh.service └─6437 /usr/sbin/sshd -D Feb 20 04:07:24 172 systemd[1]: Starting OpenBSD Secure Shell server... Feb 20 04:07:24 172 sshd[6437]: Server listening on 0.0.0.0 port 22. Feb 20 04:07:24 172 sshd[6437]: Server listening on :: port 22. Feb 20 04:07:24 172 systemd[1]: Started OpenBSD Secure Shell server.此时sshd服务正常启动,本机再次使用ssh登陆到虚拟机 $ ssh [email protected] [email protected]'s password:要求输入密码,证明ssh服务正常,问题解决 关注公众号: huangxy 一起学习,一起进步 |
CopyRight 2018-2019 实验室设备网 版权所有 |