# Disabling ssh or sshd service

**URL:** <https://hub.mender.io/t/disabling-ssh-or-sshd-service/4138>\
**Category:** General Discussions\
**Tags:** yocto, raspberry-pi-3, mender, warrior\
**Created:** [October 1, 2021, 3:30pm UTC](https://hub.mender.io/t/disabling-ssh-or-sshd-service/4138 "2021-10-01T15:30:06Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [October 1, 2021, 3:30pm UTC](https://hub.mender.io/t/disabling-ssh-or-sshd-service/4138/1 "2021-10-01T15:30:06Z")

</div>

Hello,

I am trying to disable the ssh service but I am unable to do so.  
`systemctl stop sshd.service` does not yield any results.

`systemctl list-units --type=service`  
gives me the below result

```auto

UNIT LOAD ACTIVE SUB DESCRIPTION
autoStartApp.service loaded active running AutoStart App
avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack
busybox-klogd.service loaded active running Kernel Logging Service
busybox-syslog.service loaded active running System Logging Service
console-kit-log-system-start.service loaded active exited Console System Startup Logging
dbus.service loaded active running D-Bus System Message Bus
getty@tty1.service loaded active running Getty on tty1
kmod-static-nodes.service loaded active exited Create list of required static device nodes for the current kernel
mender-grow-data.service loaded active exited Mender service to grow data partition size
mender-systemd-growfs-data.service loaded active exited Grow File System on /data
mender.service loaded active running Mender OTA update service
ModemManager.service loaded active running Modem Manager
ntpd.service loaded active running Network Time Service
ofono.service loaded active running Telephony service
rngd.service loaded active running Hardware RNG Entropy Gatherer Daemon
sshd@3-192.168.1.135:22-192.168.1.47:57854.service loaded active running OpenSSH Per-Connection Daemon (192.168.1.47:57854)
sshdgenkeys.service loaded active exited OpenSSH Key Generation
systemd-journal-flush.service loaded active exited Flush Journal to Persistent Storage
systemd-journald.service loaded active running Journal Service
systemd-logind.service loaded active running Login Service
systemd-modules-load.service loaded active exited Load Kernel Modules
systemd-networkd.service loaded active running Network Service
systemd-random-seed.service loaded active exited Load/Save Random Seed
systemd-remount-fs.service loaded active exited Remount Root and Kernel File Systems
systemd-resolved.service loaded active running Network Name Resolution
systemd-sysctl.service loaded active exited Apply Kernel Variables
systemd-timesyncd.service loaded active running Network Time Synchronization
systemd-tmpfiles-setup-dev.service loaded active exited Create Static Device Nodes in /dev
systemd-tmpfiles-setup.service loaded active exited Create Volatile Files and Directories
systemd-udev-trigger.service loaded active exited udev Coldplug all Devices
systemd-udevd.service loaded active running udev Kernel Device Manager
systemd-update-utmp.service loaded active exited Update UTMP about System Boot/Shutdown
var-volatile-cache.service loaded active exited Bind mount volatile /var/cache
var-volatile-lib.service loaded active exited Bind mount volatile /var/lib
var-volatile-spool.service loaded active exited Bind mount volatile /var/spool

LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.

35 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

```

This below sshd service is a part of a static service  
`sshd@3-192.168.1.135:22-192.168.1.47:57854.service loaded active running OpenSSH Per-Connection Daemon (192.168.1.47:57854)`

`sshd@.service` this is a static service.

Right now the only way I am getting around this is by setting the IPtables rule. But is there a way to completely shutdown the ssh service without removing it from the image.

I want to be able to turn ssh on if I have to do a remote debug?

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [October 1, 2021, 3:43pm UTC](https://hub.mender.io/t/disabling-ssh-or-sshd-service/4138/2 "2021-10-01T15:43:54Z")

</div>

It may be a template service. Try using ‘sshd@22’ instead of just ‘sshd’

Drew

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [October 1, 2021, 3:56pm UTC](https://hub.mender.io/t/disabling-ssh-or-sshd-service/4138/3 "2021-10-01T15:56:49Z")

</div>

When I ran that command. It did not close the existing ssh connection. I will try running that once the device boots up and see if that helps

Edit1 Did not work. When I try getting the status

```auto
● sshd@22.service - OpenSSH Per-Connection Daemon
   Loaded: loaded (/lib/systemd/system/sshd@.service; static; vendor preset: enabled)
   Active: inactive (dead)

```

I don’t think it ever ran

---

<div class="post-metadata">

**Author:** ![dellgreen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/dellgreen/32/85_2.png) [@dellgreen](https://hub.mender.io/u/dellgreen)\
**Post date:** [October 1, 2021, 6:27pm UTC](https://hub.mender.io/t/disabling-ssh-or-sshd-service/4138/4 "2021-10-01T18:27:16Z")

</div>

have you tried disabling the sshd.service as using stop wont disconnect any active connections or stop it from running again on next boot

`systemctl disable sshd.service`

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [October 1, 2021, 7:08pm UTC](https://hub.mender.io/t/disabling-ssh-or-sshd-service/4138/5 "2021-10-01T19:08:48Z")

</div>

I don’t think I can enable or disable service on read-only RootFs. But I will give it shot

---

<div class="post-metadata">

**Author:** ![dellgreen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/dellgreen/32/85_2.png) [@dellgreen](https://hub.mender.io/u/dellgreen)\
**Post date:** [October 1, 2021, 7:21pm UTC](https://hub.mender.io/t/disabling-ssh-or-sshd-service/4138/6 "2021-10-01T19:21:58Z")

</div>

Yer thats prob not going to work if read only as it needs to remove a symlink from /etc.

Are you trying to disable SSH completely as you don’t need it?

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [October 1, 2021, 7:36pm UTC](https://hub.mender.io/t/disabling-ssh-or-sshd-service/4138/7 "2021-10-01T19:36:56Z")

</div>

I want it disabled/stopped but I should be able to enable it again.  
Right now, I am achieving that by changing the iptables rules

---

<div class="post-metadata">

**Author:** ![dellgreen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/dellgreen/32/85_2.png) [@dellgreen](https://hub.mender.io/u/dellgreen)\
**Post date:** [October 1, 2021, 8:41pm UTC](https://hub.mender.io/t/disabling-ssh-or-sshd-service/4138/8 "2021-10-01T20:41:28Z")

</div>

so you want it disabled by default, want to be able to enable it at anytime, and are happy for it to go back to disabled when device is rebooted?

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [October 1, 2021, 9:27pm UTC](https://hub.mender.io/t/disabling-ssh-or-sshd-service/4138/9 "2021-10-01T21:27:32Z")

</div>

Yes, That is exactly what I want.

---

<div class="post-metadata">

**Author:** ![dellgreen](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/dellgreen/32/85_2.png) [@dellgreen](https://hub.mender.io/u/dellgreen)\
**Post date:** [October 1, 2021, 9:49pm UTC](https://hub.mender.io/t/disabling-ssh-or-sshd-service/4138/10 "2021-10-01T21:49:00Z")

</div>

then i would disable sshd service from starting by default in the yocto build by preventing it creating the symlink in /etc/systemd/system/ directory which should stop it starting up by default. Then whenever you need it to run temporarily execute sudo systemctl start sshd.service via whatever other access methods you have to the device.

[https://www.yoctoproject.org/docs/current/ref-manual/ref-manual.html#var-SYSTEMD\_AUTO\_ENABLE](https://www.yoctoproject.org/docs/current/ref-manual/ref-manual.html#var-SYSTEMD_AUTO_ENABLE)
