Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSH service running on multiple ports with custom rules in Linux [closed]

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.

like image 926
Gautham Sreenivasan Avatar asked Oct 23 '25 16:10

Gautham Sreenivasan


1 Answers

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:-

  1. create a copy of the SSH service and name it, here I named the copy as sshd_config_custom
cp /etc/ssh/sshd_config /etc/ssh/sshd_config_custom
  1. Similarly, create a copy of the service too.
cp /lib/systemd/system/ssh.service /lib/systemd/system/sshd-custom.service
  1. open /lib/systemd/system/sshd-custom.service using any comfortable editor and change
ExecStart=/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.

  1. Now you can add the line Port 5522 in /etc/ssh/sshd_config_custom and can make any required changes to this conf file.

  2. 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

like image 181
Gautham Sreenivasan Avatar answered Oct 25 '25 06:10

Gautham Sreenivasan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!