Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I use ssh on a variety of machines, mainly linux. Accounts on these machines vary in naming scheme: if my name is First Last, then I have accounts: first, flast, last_f, lastf, and sometimes I need to log in as root. For each machine I use, I would like the openssh client to know which account to use when I don't specify on the command line.

So the question is: How do I make ssh server Do The Right Thing when a username is not specified?

share|improve this question
add comment

2 Answers

up vote 17 down vote accepted

You can create a config file in your home .ssh directory, which can specify a default user, identity file etc and assign it to an alias which you can use to connect.

For example, you could put this into the ~/.ssh/config file:

Host example
    HostName example.com
    User first_last
    IdentityFile ~/.ssh/example_rsa
    Port 22
    RSAAuthentication yes
    PubkeyAuthentication yes

Host example2
    HostName example2.com
    User last_first
    # other parameters as needed

Then you can just type ssh example or ssh example2 on the command line to connect.

So you can set one up for each machine you want to connect to, with the relevant user. Then just use the aliases to connect without having to specify a user. You can also use a pattern to match multiple hosts.

There's more information, and details of what you can specify in a config file in the ssh_config man page.

share|improve this answer
3  
Absolutely, you can specify as many as you want in the same .config file. I have over 20 in mine with no issues. I just leave a space between each distinct Host, which probably isn't required, but makes it more readable. –  Rich Adams Nov 3 '09 at 14:06
1  
Shouldn't it be config file? Without dot at the beginning? –  danadam Nov 3 '09 at 14:21
1  
@rich was trying to get you to show another site in your example; hope you don't mind me going ahead and throwing it in. –  quack quixote Nov 3 '09 at 14:57
4  
Indenting everything but lines that contain "Host foo" greatly helps the maintainability cause. –  innaM Nov 3 '09 at 16:42
1  
@CristianCiupitu: Considering the is a Linux question, I'd hardly call the OpenBSD's man page the official one. There are options in Linux's ssh (e.g., GSSAPIKeyExchange) that aren't available in the BSD version. –  Dennis Mar 30 at 15:15
show 7 more comments

According to Rich Adam's answer I found out for PuTTY where it stores its settings.

It's all stored in a registry tree, you'll find it under HKEY_CURRENT_USER\Software\SimonTatham (Simon Tatham is the developer of PuTTY).
There you can see how a host is defined.

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.