Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to mux between two ssh servers based on incoming username i.e.

ssh user1@testserver will go to one sshd instance and user2@testserver goes to another.

Can this be done?

share|improve this question
    
Just have everything go to one server, then setup a ForceCommand to connect to the other server? –  Zoredache Jan 23 at 6:15
    
WHY do you want to do this -- What actual, practical, real-world problem are you trying to solve? There is almost certainly a better solution than what you're suggesting. –  voretaq7 Jan 24 at 18:03
add comment

2 Answers 2

up vote 1 down vote accepted

No. Everything in an ssh session is encrypted. How do you propose the proxy would be able to snoop on the username?

share|improve this answer
    
I was hoping the sshd instance could serve as the proxy! –  Amaterasu Jan 23 at 4:16
add comment

I think you can do this with ForceCommand, like:

ForceCommand proxyscript

in /etc/sshd/sshd_config. Here proxyscript would be a custom script that would ssh to whatever the next server should be, depending on which user is running it. The script would have enough information to do that because according to the man page for sshd_config, it will run under the user's login shell, so for example $USER will be available.

If you only have a small, fixed set of users who you want to do this for, then you can configure it all in sshd_config with for example

Match User user1
ForceCommand ssh user1@host1

Match User user2
ForceCommand ssh user2@host2

But I don't know if this would correctly hook up the standard out/in of the incoming connection to standard in/out of the new ssh command.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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