Last Updated: September 09, 2019
·
6.494K
· michie1

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.

9 Responses
Add your response

such a simple thing and one I'd not come across. works great too. Thanks!

over 1 year ago ·

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
over 1 year ago ·

You can also use wildcards, conveniently - for instance, if you have a different username at work:


Host *.work.com
User dave
</pre>
over 1 year ago ·

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.

over 1 year ago ·

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.

over 1 year ago ·

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.

over 1 year ago ·

And you can use these aliases everywhere, for example in Git/Subversion/Bazaar repository URLs, which simplify a lot!

over 1 year ago ·

I use this in Linux: It doesn't even ask for password this way:

sshpass -p 'password' ssh -o StrictHostKeyChecking=no username@server
over 1 year ago ·

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.

over 1 year ago ·