ytzexq
Last Updated: February 25, 2016
·
1.52K
· michie1
78ac7450752d7b4882df4c6e53e230db

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.

Say Thanks
Respond

9 Responses
Add your response

14416
Avatar 942 normal

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

over 1 year ago ·
14417
Ccf73970579fd055ef53a4a2352c3875

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
E77a97b7bec8a0dc42fee8ecb640cb25

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
78ac7450752d7b4882df4c6e53e230db

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
3f23a52c7bc87296e96b5a05547da0e0

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
32ef4e3e388cbadc756a008cade3ee6a

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

over 1 year ago ·
14574
5a999be4e1553fb640132d205152fa38

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
985d2865248f78c1b32ab6f26e38969b

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 ·
Filed Under