Fork me on Gitee

centos 8 sshd 无法连接

本文讲述通过Windows端的软件WinSCP通过ssh协议连接VM下的linux centos8。连接的原理图如下:

 

 

 所以,centos系统上必须安装openssh-server,类似于服务器端。(因为是使用Windows下的软件来访问linux,所以Linux下不需要安装openssh的客户端)openssh-client在Windows下的很多软件中都支持,如上图所示软件,所以本文的重点是配置linux下的ssh服务器。

1.查看centos中是否安装了openssh-server。查看命令:yum list installed | grep openssh-server

 

 

 

上图显示已经安装,如果没任何输出显示表示没有安装 openssh-server,通过输入 yum install openssh-server来安装。

2.修改 /etc/ssh/ 目录下的sshd服务配置文件 sshd_config。(注意一定是sshd_config文件,如果系统中安装有openssh-client,就会有ssh_config文件,别找错了文件)
vi /etc/ssh/sshd_config (以下是一些基本配置)

Port 22  #定义ssh监听的端口号,默认为22 
ListenAddress 0.0.0.0  #设置ssh服务器绑定的ip地址,默认为所有可用的ip地址 

 

 

PermitRootLogin yes #设置是否允许root登录,默认允许

 

 

 #PermitEmptyPasswords no #设置是否允许空密码的客户登录,默认为禁止

PasswordAuthentication yes #设置是否使用口令认证方式,如果要使用公钥认证方式,可将其设置为no

 

 

 

 3.启动sshd服务。

service sshd start 启动sshd服务。
ps -e | grep sshd 检查sshd服务是否已经启动。

systemctl status sshd.service

将sshd服务添加之自启动列表中,并查看是否开启自启动sshd服务。
systemctl enable sshd.service
systemctl list-unit-files | grep sshd

 

 

 4.确认centos和PC之间网络互通,并且查看centos的ip地址。

这里在centos上访问外网来验证网络是通的。

 

ifconfig -a 查看centos的ip地址。

 

 5.使用winscp来连接访问centos8。

 

 

 

posted @ 2021-12-20 17:07  JoePotter  阅读(763)  评论(0编辑  收藏  举报
``