Use Aliases to Create SSH Shortcuts

Apr 11, 2011 - 12 Comments

Terminal in macOS

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'

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.


Related articles:

Posted by: David Mendez in Command Line


» Comments RSS Feed

  1. […] 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 […]

  2. Jeff says:

    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..

    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..

  3. Jeff says:

    I just make little files in /usr/bin by doing the following..

    open terminal

    sudo vi /usr/bin/butter
    sudo chmod 755 /usr /bin/butter

    then when you open terminal you type butter

    whammo you are in

  4. […] 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 […]

  5. Ryan says:

    Using ~/.ssh/config to do this is highly recommended instead of aliasing.
    In ~/.ssh/config file

    Host myhost
    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.

  6. […] 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 […]

  7. Vijay Kumar says:

    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?

    • Doug Jaworski says:

      You are probably best of using ssh keys. utilizing the key method will eliminate the need for a password.

    • David says:

      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.

    • Bink of Boldhome says:

      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.

Leave a Reply


Shop on and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks


iPhone / iPad



Shop on Amazon to help support this site