Automatically set SSH user
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?
Solution 1:
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.
Solution 2:
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