重新启用sshd服务

一、环境

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.6 LTS
Release:	18.04
Codename:	bionic

二、背景

在安装了openssh-server后,将自动将sshd加入到自启动服务中

$ sudo apt install openssh-server

某天觉得不需要sshd自启动时,将sshd停用,并禁用了sshd

$ systemctl stop sshd
$ systemctl disable sshd
Removed /etc/systemd/system/sshd.service.
Removed /etc/systemd/system/multi-user.target.wants/ssh.service.

某天需要远程ssh连接时,开启sshd, 启用失败

$ systemctl enable sshd
Failed to enable unit: Unit file sshd.service does not exist.

三、解决方案

方案一、 卸载重装

最暴力的方式,直接卸载了再重新安装

$ sudo apt remove openssh-server --purge -y
$ sudo apt install openssh-server

方案二、建立软连接

细心的人会发现,在disable时只是删除了systemd中的软连接,恢复软连接就可以恢复正常。

$ sudo ln -s /lib/systemd/system/ssh.service /etc/systemd/system/sshd.service
$ sudo ln -s /lib/systemd/system/ssh.service /etc/systemd/system/multi-user.target.wants/ssh.service

可以看到已经恢复正常

$ systemctl start sshd

$ ps aux | grep sshd
root      6846  0.0  0.0  72304  5660 ?        Ss   09:52   0:00 /usr/sbin/sshd -D
  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值