CentOS 7.7 远程SSH连接不上问题解决

1.检查主机与目标服务器是否能相互ping通

在主机上 cmd --> telnet 192.168.199.227 22  -- 目标机器的ip、端口

如果主机无法使用telnet命令,则需要打开Telnet客户端,控制面板 --> 程序 --> 卸载或更改程序 --> 打开或关闭Windows功能 --> 选中 Telnet客户端

2.查看linux是否安装ssh服务

登录 root 用户下

命令:ssh localhost 

如果提示 "ssh:connect to host localhost port 22:connection refused",就说明没有打开ssh服务或者未安装ssh服务.

(1)如果linux系统是 ubuntu linux 版本,执行命令:sudo apt-get install openssh-server 安装ssh服务,在提示时都选择yes,然后会自动安装ssh服务.

(2)如果linux系统是 centos linux 版本,查看ssh是否安装,执行命令:rpm -qa | grep ssh 

 如果没有安装过ssh服务,则执行命令:yum install openssh-server 安装

3.安装完成后输入命令(root用户下)

 启动ssh服务命令:service sshd start 

 重启SSH服务:service sshd restart

 停止ssh服务命令:service sshd stop 

 查看ssh服务22端口是否启动命令:netstat -antp | grep sshd

 查看ssh服务进程命令:ps -ef|grep ssh

    设置ssh服务为开机启动命令:chkconfig sshd on 

 设置ssh服务禁止开机启动命令:chkconfig sshd off 

 

具体操作:

[root@centos01 ~]# ssh localhost
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is SHA256:2LmA8OrgIY4wtuI+92d6t0xk6zleY3obJmkyh4E2tuA.
ECDSA key fingerprint is MD5:ed:ed:80:68:1f:47:a6:bc:73:b3:bc:9d:63:6b:c1:5c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
root@localhost's password: 
Last login: Sun Apr 26 17:51:19 2020
[root@centos01 ~]# rpm -qa | grep ssh
openssh-clients-7.4p1-21.el7.x86_64
libssh2-1.8.0-3.el7.x86_64
openssh-7.4p1-21.el7.x86_64
openssh-server-7.4p1-21.el7.x86_64   -- 说明已经安装了ssh
[root@centos01 ~]# ps -ef|grep ssh
root       1301      1  0 16:15 ?        00:00:00 /usr/sbin/sshd -D
root      54071  53935  0 17:51 ?        00:00:00 /usr/bin/ssh-agent /bin/sh -c exec -l /bin/bash -c "env GNOME_SHELL_SESSION_MODE=classic gnome-session --session gnome-classic"
root      55734  54650  0 18:40 pts/0    00:00:00 ssh localhost
root      55735   1301  0 18:40 ?        00:00:00 sshd: root@pts/1
root      55742  53930  0 18:41 ?        00:00:00 /usr/bin/ssh-agent -D -a /run/user/0/keyring/.ssh
root      55815  55750  0 18:43 pts/1    00:00:00 grep --color=auto ssh
[root@centos01 ~]# ps -ef | grep ssh | grep -v grep
root       1301      1  0 16:15 ?        00:00:00 /usr/sbin/sshd -D
root      54071  53935  0 17:51 ?        00:00:00 /usr/bin/ssh-agent /bin/sh -c exec -l /bin/bash -c "env GNOME_SHELL_SESSION_MODE=classic gnome-session --session gnome-classic"
root      55734  54650  0 18:40 pts/0    00:00:00 ssh localhost
root      55735   1301  0 18:40 ?        00:00:00 sshd: root@pts/1
root      55742  53930  0 18:41 ?        00:00:00 /usr/bin/ssh-agent -D -a /run/user/0/keyring/.ssh
[root@centos01 ~]# service sshd start
Redirecting to /bin/systemctl start sshd.service
[root@centos01 ~]# ps -ef|grep ssh|grep -v grep
root       1301      1  0 16:15 ?        00:00:00 /usr/sbin/sshd -D
root      54071  53935  0 17:51 ?        00:00:00 /usr/bin/ssh-agent /bin/sh -c exec -l /bin/bash -c "env GNOME_SHELL_SESSION_MODE=classic gnome-session --session gnome-classic"
root      55734  54650  0 18:40 pts/0    00:00:00 ssh localhost
root      55735   1301  0 18:40 ?        00:00:00 sshd: root@pts/1
root      55742  53930  0 18:41 ?        00:00:00 /usr/bin/ssh-agent -D -a /run/user/0/keyring/.ssh
[root@centos01 ~]# netstat -antp | grep sshd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1301/sshd           
tcp6       0      0 :::22                   :::*                    LISTEN      1301/sshd           
tcp6       0      0 ::1:22                  ::1:41754               ESTABLISHED 55735/sshd: root@pt 
[root@centos01 ~]# ps -ef | grep ssh | grep -v grep
root       1301      1  0 16:15 ?        00:00:00 /usr/sbin/sshd -D
root      54071  53935  0 17:51 ?        00:00:00 /usr/bin/ssh-agent /bin/sh -c exec -l /bin/bash -c "env GNOME_SHELL_SESSION_MODE=classic gnome-session --session gnome-classic"
root      55734  54650  0 18:40 pts/0    00:00:00 ssh localhost
root      55735   1301  0 18:40 ?        00:00:00 sshd: root@pts/1
root      55742  53930  0 18:41 ?        00:00:00 /usr/bin/ssh-agent -D -a /run/user/0/keyring/.ssh
[root@centos01 ~]# chkconfig sshd on     -- 设置开机启动ssh服务
注意:正在将请求转发到“systemctl enable sshd.service”。
[root@centos01 ~]# 
 

你可能感兴趣的:(ssh)