Changing the SSH port on Arch Linux

published 2019-05-04,updated 2020-04-07

April 2020 update

This article is out of date. Arch Linux stopped shipping OpenSSH with socket activation [1] due to the risk of DoS attack. Now you can just set `Port` in `sshd_config` as usual.

1: https://bugs.archlinux.org/task/62248

Original article

I often change the default SSH port from 22 to something else on servers I run. It kind of is a dangerous operation, especially when the only way you have to connect to that server is SSH.

The historical way to do this is editing `sshd_config` and setting the `Port` variable, but with recent versions of Arch Linux and the default configuration, this will not work.

The reason is that SSH is configured with systemd socket activation. So what you need to do is run `sudo systemctl edit sshd.socket` and set the contents of the file to:

where `MY_PORT` is the port number you want.

I hope this short post will avoid trouble for other people, at least it will be a reminder for me the next time I have to setup an Arch server...

Proxied content from gemini://separateconcerns.com/2019-05-04-ssh-port.gmi (external content)

Gemini request details:

Original URL
gemini://separateconcerns.com/2019-05-04-ssh-port.gmi
Status code
Success
Meta
text/gemini;lang=en_US
Proxied by
kineto

Be advised that no attempt was made to verify the remote SSL certificate.