SSH Command Line Tip

I use SSH a lot, for the this web site, and a few others, plus all my Cisco devices. It can get a bit confusing to keep track of all the hosts, etc. What I do to make things a little easier is to create a small Bash shell script that will connect to the host that is in the first argument ($0) that gets passed to the script, now you might be thinking to yourself how do I change $0, it’s always the name of the script. Before I go on, here is the simple Bash script I created for this tip

SSHBIN=$(which ssh)
$SSHBIN $(basename $0)

Place this script any where that is in your PATH, I add the directory ~/bin to the PATH variable, so that I were I placed by script. Now to easily connect to one of your favorite SSH hosts, just symlink to the script using the host name you use to connect.

bin$ ln -s [email protected] 

Now we can just type, or my favorite part, use command line completion (tab) if you have dozens of hosts symlink’d to the script.

$ [email protected]

You will want to make use of certificates so you don’t have to remember passwords, and make the login seamless.

Mar 31st, 2012 • Posted in Linux, Management, SSH
No comments yet.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>