How to run multiple sshd instances on raspberry pi

Facebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Why you may need this

There are different use cases, the most common would be to run two ssh servers with different configurations on different ports – one serving for local network and less restrictive (allow all users, password authentication, etc) and another one with more restrictions for accessing your PI from internet via port forwarding on your router.

How to build

In order to achieve the goal we will create a new systemd service, similar to standard ssh service but running as a different process and using different configuration file.

Make a copy of sshd_config

Use editor of your choice (I use Nano) and make desired changes to your new configuration file.

Make a copy of ssh.service

ssh.service is a standard ssh server service. We will create a copy of it with some modifications in order to run second instance of ssh service as a separate service.

Now make necessary changes to ssh-outside.service, so our new instance will use different config and pid files.

Save all your work.

Install the service and reboot

Test

After reboot you should be able to connect both to the default port 22 (with password) and to the port NNNN specified in your config file (only with the keys properly set up). Check this article if you have troubles with configuring SSH keys.

If you have trouble connecting to the alternative ssh port, connect using default port and troubleshoot. Start point for troubleshooting would be to check the status of your newly created service.

If everything works fine, you can now set up port forwarding on your router and access your Raspberry Pi from outside world in a way more secure manner.

Facebook Comments
Facebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Leave a Reply

Your email address will not be published. Required fields are marked *