SSH alias
Normally you would use "ssh username@server" to login, but you can make an alias.
Open .ssh/config and add the following lines.
Host aliasname
HostName servername
User username
Now you can login with "ssh aliasname", so you don't need to typ in your username and server everytime.
Written by Michiel
Related protips
9 Responses
such a simple thing and one I'd not come across. works great too. Thanks!
Also useful if you use multiple ssh keys for work and home
Host hosthere
Hostname hostname.com
User username
IdentityFile /home/username/.ssh/id_work
You can also use wildcards, conveniently - for instance, if you have a different username at work:
Host *.work.com
User dave
</pre>
You can do it in your shell .rc file at your home dir. No need to change any system files.
Bash for example:
alias name='ssh [param] user@host'
And now you can connect just typing "name" (without quote) in your shell.
Nice additions tyrelsouza and bigpresh. There is a lot more possible to configure. This tip was intended for people like whiskybae. People who know how to read the manual, but didn't know why they should read the manual.
@letskiy. Yes, what you suggest is also possible, but the method described in the tip doesn't change system files. It's only a file in your home directory. Second thing, this method also works with scp. You can do scp aliasname:/home/username/file ./ to download a file to your directory, which is not possible with your bash alias.
Yeah I do this as I have a number of places to ssh into. Great tip, I'd be surprised if most people werent doing this.
And you can use these aliases everywhere, for example in Git/Subversion/Bazaar repository URLs, which simplify a lot!
I use this in Linux: It doesn't even ask for password this way:
sshpass -p 'password' ssh -o StrictHostKeyChecking=no username@server
This is an essential technique I use to manage repos from multiple endpoints. With Bash shortcuts, one can make this as simple as a single command.