Enable SSH server sshd on raspbian

Revision history
Tags: raspbian raspberrypi ssh

In raspbian, theres a systemd service sshswitch.service that checks whether a certain file exists or not.

[Unit]
Description=Turn on SSH if /boot/ssh is present
ConditionPathExistsGlob=/boot/ssh{,.txt}
After=regenerate_ssh_host_keys.service

[Service]
Type=oneshot
ExecStart=/bin/sh -c "update-rc.d ssh enable && invoke-rc.d ssh start && rm -f /boot/ssh ; rm -f /boot/ssh.txt"

[Install]
WantedBy=multi-user.target

This means that to enable the sshd.service on a fresh install of raspbian you can create an empty file at /boot/ssh.

You can do this without power the Pi, by, for example:

# mkdir -p /mnt/boot
# mount /dev/mmcblk0p1 /mnt/boot
# touch /mnt/boot/ssh
$ sync
# umount /mnt/boot

And the sshd should be running on the next boot.

If you have any comments or feedback, please send me an e-mail. (stig at stigok dotcom).

Did you find any typos, incorrect information, or have something to add? Then please propose a change to this post.

Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.