ytzexq
Last Updated: February 25, 2016
·
2.339K
· 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

14416

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

over 1 year ago ·
14417

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 ·
14425

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 ·
14466

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 ·
14469

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 ·
14527

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 ·
14542

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

over 1 year ago ·
14574

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 ·
14616

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 ·