I.T. Security and Linux Administration

Sep 13 2010   10:36AM GMT

SSH and the alias Features

Eric Hansen Eric Hansen Profile: Eric Hansen

When working with any *nix-based system, I’ve found that SSH becomes a part of your life…almost as if you’re married to it for the 9 (or 12…) hours you are at work.  But, I see many people just constantly type the same command over and over again.  While I’m not going to cover the ideals as to why this is bad for productivity, I will cover, however, a simple and easy trick to make using SSH faster and easier.

I discovered this while on my job (never messed with aliases before).  Our sysadmins were kind enough to make it easy for us to log into the abundance of servers that we house (both on-site and off).  Essentially we have two root accounts we have to log into before we can do anything.  One is a generic support account that basically only has sudo access, and then there’s root.  While I don’t agree root should be enabled, that’s not a topic for this post.  But, getting bored one day (weekends tend to be a slow day), I poked through the .bashrc file on “our” server (our SSH protocol is strange…), and found that the short commands we use to get to the generic support account is just a function aliased with simplicity.

This got me thinking, especially since I do work from home when I’m bored, and I have 2 servers of my own I manage.  How would I go about setting this up myself.  While I liked how it was done at my work, I like to keep things as close-knit as possible.  So, I developed this little gem (originally it had switches and was more advanced, but I have since reformatted, lost my .bashrc and decided to recode it for the 10th time anywho):

function ssh_call ()
case "$1" in
# ssh to vps

alias vps='ssh_call vps'
alias home='ssh_call home'
alias work='ssh_call work'

You can hard code the SSH commands and such in the alias, I just did it this way ’cause I was working on how to use functions properly in shell scripting, and so this was sort of a mini-project for me. Put that in your .bashrc script and either restart the terminal or run source ~/.bashrc and you should be set (shouldn’t give errors, it works for me). Now all you got to do is type in any of the alias names (whatever is between “alias ” and “=”), and it’ll connect you. This is highly helpful when you have long commands to type.

I’m sure this will be helpful to at least a few people out there. This obviously works for more than just SSH too (the starter aliases are for ls commands), so if you have any nifty alias tricks, or any .bashrc tricks to show off, feel free to post them here.

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: