change default username when ssh to another pc [duplicate]

When I ssh between different pcs I can omit my username (tom) and just type

ssh pc_name

instead of

ssh tom@pc_name

I like this feature, and have got into the habit of using it.

Unfortunately, on one of my computers I went for the user name tommy. Everytime I connect to this computer I forget to write tommy@creative_pc and wonder why my password doesn't work. Is there a way to tell ssh what user name to use when the username is omitted?

Edit: Just found the following question that is similar: How to make ssh log in as the right user? It didn't come up on my initial search.


Solution 1:

Sure:

$ ssh -l tommy

will log you in as tommy.

You can also make this persistent per-host by having a record like this in ~/.ssh/config:

Host creative_pc
User tommy
HostName creative_pc # put the full host name here or the IP if it is static

then you just do:

$ ssh creative_pc # this is the string from Host setting

and you login there as tommy by default

Solution 2:

I have a large list of servers, so I used a shell alias to set a default user for all hosts. Put bellow line on your ~/.bashrc:

alias ssh="ssh -l default_user"

You can still set another user, using -l:

ssh server -l other_user

I started using today, seems working fine on Ubuntu 12.