Command line shortcut for lengthy SSH commands

May 31, 2007 - 4 Comments

We love tips that make your computing life easier, and this command line tip from Cedrik Morgan falls into that category:

“If you have a server that you commonly access a nice way to avoid typing a lengthy command like ‘ssh 192.168.1.100 -l admin’ over and over again is to create an alias in your .profile, here’s how to set it up:

From the command line use a text editor, I’ll suggest nano because it’s easy to use, type:
nano .profile
and add the following line to your .profile:
alias servername="ssh serverIP.com -l username -p port"
now instead of typing out the ful ‘ssh serverIP blah blah’ command, you can just type servername, much easier! “

Thanks Cedrik! We’ve covered the alias command a bit in the past with the article titled Launching GUI Applications from the Terminal, check it out for more info.

Related articles:

Posted by: Bill Ellis in Command Line, Mac OS X, Tips & Tricks

4 Comments

» Comments RSS Feed

  1. Weaver says:

    not a bad tip, but I think Cedrik must have been living under a rock for 10 years because the alias command has been used in unix for eternity

  2. Dave Smith says:

    Use ~/.ssh/config for this sort of thing. Look at

    man ssh_config

  3. lar3ry says:

    Here’s a way to do make an alias permanent without having to resort to a text editor in bash:

    add_alias ()
    {
    local aname=$1;
    shift;
    echo “alias $aname=\”$@\”" | tee >> “$HOME/.bashrc”;
    eval “alias $aname=\”$@\”"
    }

    Once this handy function is in your .bashrc, you can just type:

    $ add_alias servername ssh -p 800 username@servername

    That will create the alias “servername” and add it to the end of your .bashrc so the next time you start up a terminal session, the alias will be available again.

  4. Alaina says:

    I love aliasing, but for this, ~/.ssh/config is an infinitely superior solution.

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

OSXDaily on Facebook

OSXDaily on Google+

Shop at Amazon

Ad

Shared on Facebook