1

I multiple SSH servers on the same hostname and I want to use a default username for the ssh server running on one port and another one for the second ssh server. Is this possible?

2

From man sshd:

-f config_file Specifies the name of the configuration file. The default is /etc/ssh/sshd_config. sshd refuses to start if there is no configuration file.

So, invoke the sshd server instances with separate configuration files.

1

There is no pretty solution, but it is possible using a Match exec section in ssh_config.

From man ssh_config:

The exec keyword executes the specified command under the user's shell. If the command returns a zero exit status then the condition is considered true. Commands containing whitespace characters must be quoted. The following character sequences in the command will be expanded prior to execution: ‘%L’ will be substituted by the first component of the local host name, ‘%l’ will be substituted by the local host name (including any domain name), ‘%h’ will be substituted by the target host name, ‘%n’ will be substituted by the original target host name specified on the command-line, ‘%p’ the destination port, ‘%r’ by the remote login username, and ‘%u’ by the username of the user running ssh(1).

This means that we can let ssh execute /usr/bin/test to match the port (here 2222):

Match host "your_host" exec "test 2222 -eq %p"
    User another_user

Alternatively you can define a nickname/alias for your SSH server on the other port:

Host server_with_other_port
    Port 2222
    User another_user

Then you are able to connect to the second SSH server using ssh server_with_other_port and the different default port and default user name will be applied.

The caveat of the alias solution is that the default user name is only applied if you use the alias, not if you use the real server name or the IP address.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.