Use Aliases to Create SSH Shortcuts

Apr 11, 2011 - 12 Comments

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.

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.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: David Mendez in Command Line

12 Comments

» Comments RSS Feed

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

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

  3. Ryan says:

    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.

  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. Jeff says:

    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

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

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

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

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

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