Use Aliases to Create SSH Shortcuts
More fun with SSH! We showed you how to setup SSH config files and use tab completion for SSH aliases, but setting up bash aliases is even easier if you are connecting to the same server over and over again.
How to Add an SSH Shortcut to Command Line with Alias
Here’s what you’ll need to do:
nano ~/.bash_profile
On a new line, enter something like this:
alias servername='ssh -p 888 user@server.domain.com'
Hit Control+O to save then Control+X to exit nano, and relaunch the Terminal.
Now you only have to type ‘servername’ and off you go.
A few of our commenters pointed this out as an even easier method to connect to a server than setting up a config file specifically for SSH. Thanks for the input everyone.
[…] you go the latter route, you’d best off creating an alias in bash_profile. For the purpose of this article we’ll assume you installed it through […]
I forgot to mention I type them all up and then place them in dropbox and when I do a fresh install I will do this..
Terminal
/Users/Jeff/Dropdox
sudo cp -R /ssh_sites/ /usr/bin
then they are all back in there so I don’t have to keep typing them out over and over..
I just make little files in /usr/bin by doing the following..
open terminal
sudo vi /usr/bin/butter
ssh jeff@butter.net
:wq!
sudo chmod 755 /usr /bin/butter
then when you open terminal you type butter
whammo you are in
[…] you may want to set a manual DHCP IP address so that it doesn’t change on you, and then setup an SSH alias so you don’t have to type the entire connection string […]
Using ~/.ssh/config to do this is highly recommended instead of aliasing.
In ~/.ssh/config file
Host myhost
Hostname server.domain.com
User user
Port 888
then you may just type “ssh myhost” and will have exactly same effect, except that it’s done in the RIGHT way.
YAY, you’re right!
I went the config route. Works great!
[…] could combine this tip with using aliases to create shortcuts and eliminate the need for the lengthy command. An example to put in your .bash_profile would […]
Thanks for the hint. However if your password is more complex than 888, it does not work. Do I need to escape that? For example password is “Ab$234.” what should be the alias command line?
You are probably best of using ssh keys. utilizing the key method will eliminate the need for a password.
For security purposes I would recommend requiring the input of your password manually on each connection, or as Doug recommends, using an SSH key. It’s generally not a good idea to have passwords openly readable in plain text.
The 888 value is not a password, it specifies the port on which the SSH server is listening. This hint only marginally better than useless since using the ~/.ssh/config file is 1) not that difficult and 2) doesn’t have to be sourced upon modifying it.