当我们使用一台服务器的时候,经常需要开启ssh 服务,有些系统没有默认开启服务,需要需要我们做一些配置,以下是完整配置过程和错误解决方法:

以下过程适合于当我们购买一台云主机时候配置远程登录

开启本地计算机的22端口

Failed to restart sshd.service: Unit sshd.service not found

1、 查看是否安装 openssh-server:yum list installed | grep openssh-server

yum install openssh-server 安装sshd服务

Ubuntu : apt-get install openssh-server 安装sshd服务

3、进入/etc/ssh/目录下找到配置文件sshd_config,用Vim编辑器打开。命令 vim sshd_config,修改以下内容

设备端口 ssh 端口22

3.2、开启允许远程登录

PermitRootLogin yes

3.3、开启使用用户名密码来作为连接验证

PasswordAuthentication yes

systemctl start sshd.service && systemctl enable sshd.service

root@xxx:~# sudo service sshd restart

Failed to restart sshd.service: Unit sshd.service not found.

第五步,执行重启命令

root@xxx:~# systemctl enable ssh.service

Synchronizing state of ssh.service with SysV service script with /lib/systemd/systemd-sysv-install.

Executing: /lib/systemd/systemd-sysv-install enable ssh

Created symlink /etc/systemd/system/sshd.service → /lib/systemd/system/ssh.service.

第六步以及第七步,查看端口号

root@xxx:~# service sshd start

root@xxx:~# ss -ntl

State    Recv-Q    Send-Q        Local Address:Port        Peer Address:Port   

LISTEN   0         128                 0.0.0.0:22               0.0.0.0:*      

LISTEN   0         128                    [::]:22                  [::]:*  

启动sshd失败,报错:Failed to start OpenBSD Secure Shell server

 

  1. apt-get install openssh-server openssh-client
  2. 执行  /etc/init.d/ssh start
  3. 报错 Could not resolve hostname start

          ss -ntl    22端口打开

  1. 远程ssh登录成功

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐