I was working on setting up a server with SSH service running on multiple ports like say, port 22, and 5522 and these port should be having a different set of rules, ie: The rules we added for port 22 should not conflict with the rules for port 5522.
Initially, the SSH service can be made to listen to multiple ports by adding the following line to /etc/ssh/sshd_config.
Port 22
Port 5522
In this scenario, you cannot define different rules for different ports.
One of the solutions I could find is to create a new service to run SSH service on port 5522 and then running the service as daemon.
To do so please follow steps below:-
sshd_config_customcp /etc/ssh/sshd_config /etc/ssh/sshd_config_custom
cp /lib/systemd/system/ssh.service /lib/systemd/system/sshd-custom.service
/lib/systemd/system/sshd-custom.service using any comfortable editor and changeExecStart=/usr/sbin/sshd -D $SSHD_OPTS
to
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS -f /etc/ssh/sshd_config_custom
And
Alias=sshd.service
to
Alias=sshd-custom.service
Save and exit the file.
Now you can add the line Port 5522 in /etc/ssh/sshd_config_custom and can make any required changes to this conf file.
Enable and start the custom service that we have created.
systemctl enable sshd-custom.service
systemctl start sshd-custom.service
Let me know if there is any other suggestions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With