8

I have one ssh server that I seldom connect to and which requires to use a different user than the one I use to log in to my system. When I just execute ssh example.com then ssh will automatically use my default user [email protected] to connect. This will not work, because the server expects me to connect with a special user [email protected]. Additionally, the server has a strong blocking and banning policy. So when I use the wrong password a few times, then I am automatically blocked for half an hour or even banned. Because I connect so seldom, I tend to forget that I need to use a special user to connect, and it can be very annoying if I am blocked for half an hour or even banned.

What I am looking for is a way configure my local ssh client and tell it: "When ever I am connecting to example.com, I want you to automatically connect with user xyz12345 and not with my current user."

Is something like this possible?

2 Answers 2

34

You can set it up in your ssh client config.

Add to your .ssh/config

Host example.com
     User xyz12345

From man ssh_config:

User     Specifies the user to log in as. This can be useful when a dif-
         ferent user name is used on different machines.  This saves the
         trouble of having to remember to give the user name on the com-
         mand line.
1
1

I would use an alias in your ~/.<shell>rc script:

alias mycmd='ssh [email protected]'

then type:

source ~/.<shell>rc

But you can also do this: A way better

3
  • I was rather looking for something that directly affects ssh. As I said, I will not connect to this server so often and I tend to forget that I need to use a special user, so I will likely also forget that I have setup an alias and just try to connect with ssh example.com. I want a way such that ssh actively prevents me from doing this. Either by warning me or by automatically using the correct user for this particular server.
    – lanoxx
    Apr 3, 2015 at 11:31
  • I understand, I added a link in my answer, the solution is a way better. Apr 3, 2015 at 11:32
  • Perfect, thats exactly what I was looking for.
    – lanoxx
    Apr 3, 2015 at 11:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .