30

I have a different (assigned, non-changable) username on one of the servers I log to regularly, and I would like to avoid writing it down every time. Can I make these lines

[tohecz@localhost ~]$ ssh myserver.cz
[tohecz@localhost ~]$ ssh anotherserver.cz

behave as the following?

[tohecz@localhost ~]$ ssh [email protected]
[tohecz@localhost ~]$ ssh [email protected]
9
  • 1
    Can I ask why the question got downvoted? Have I done anything wrong? If so, please exaplain it to me so that I can improve the post.
    – yo'
    Commented Apr 24, 2014 at 12:22
  • 2
    I did not DV this but typically Q's that are very basic such as this or show little effort in searching prior to asking are viewed negatively. Also searching this site would've yielded many A's that show the below A: unix.stackexchange.com/search?q=ssh+user+host
    – slm
    Commented Apr 24, 2014 at 12:56
  • 1
    @tohecz Looking at man ssh_config and searching for User gives the result in about 30 sec. So, as slm says, it is very basic. I'm not suggesting asking such a question is a bad thing - one does have to know where to look, and that may not be obvious. I ask basic questions sometimes too, but some people may not like it. I'm also not justifying the downvote. I don't believe in them, except for spam. Commented Apr 24, 2014 at 14:49
  • 2
    @FaheemMitha That sounds like I should know where to look. I consider any further discussion in this manner pointless.
    – yo'
    Commented Apr 24, 2014 at 15:03
  • 1
    @tohecz At the risk of redundancy, no disrespect or offense to you is intended. This was by way of response to you asking about the downvote. Commented Apr 24, 2014 at 15:09

2 Answers 2

43

Add the following in your ~/.ssh/config file:

Host myserver.cz
  User tohecz

Host anotherserver.cz
  User anotheruser

You can specify a lot of default parameters for your hosts using this file. Just have a look at man ssh_config for other possibilities.

2
  • 8
    Regarding other default parameters, I like shortening the host, along the lines of Host web / Hostname www.mysite.com / User foo
    – Kevin
    Commented Apr 24, 2014 at 17:48
  • why only link to a web site for documentation that would be installed on almost every system with the openssh client installed? links die. local man pages are forever. at least mention that the info is available by running man ssh_config.
    – cas
    Commented Nov 10, 2015 at 9:43
2

How to have default and host-specific users

To be clear, if you want BOTH a default user AND host-specific users, you need to use Host *, and put it at the bottom of the config file:

~/.ssh/config:

#
# Aliases
#

Host dev
    Hostname dev.example.com

Host mac
    Hostname mac.local


#
# Host-specific users
#

Host dev dev.example.com
    User root

Host mac mac.local
    User me


#
# Default user
#

Host *
    User app

References

You must log in to answer this question.

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