Home » Linux Unix Hacking

Automating Linux Admin From Windows Over SSH

27 September 2009 2 Comments

Today’s tip is on performing and automating simple Linux administration tasks from a Windows workstation over SSH… Creating backups, restarting services, rebooting machines, and basically any other simple administrative task can be accomplished securely from the command line in Windows, or from a desktop shortcut…

To accomplish these tasks, we’ll be using plink which is a free command line SSH client from the developers of PuTTY… plink allows you to create SSH connections from the command line, very similar to the way you would use the ssh client on a Linux machine… This means that we can use plink from within batch files, as well as pipe and redirect data to and from remote connections…

plink can be downloaded from here

After you have downloaded and placed plink in your path, you are ready to start creating shortcuts to some simple routine Linux administration tasks… The examples below are just a few of the possibilities, so please drop a comment is you have ideas for additional examples…

Before proceeding with any of the examples, you should probably connect to the server using plink once to add the server to the key cache and also to ensure that you can actually connect to the box… Open a command prompt and type the following, replacing with your user and hostname information…

plink user@host

The first example will be to create and transfer a zipped tarball of a directory on a remote server… This example could also be placed into a batch file to be run as a nightly backup scheduled task… The command is as follows:

plink -pw password user@host “tar czf – /dir_to_be_backed_up” > filename.tar.gz

This command connects to the remote machine, creates a zipped tarball of a directory, and outputs it to STDOUT… In our case the STDOUT is being redirected to a local file named filename.tar.gz… This connection will not prompt for the password as it is being supplied in the plink parameters…

The next command will restart a service on the remote server… We will not include the password in this command, as the root user is most likely required for the service restart… This example assumes you have a Red Hat based distribution, so you’ll need to modify to suit your particular server… When the command is run, it will prompt you for your password…

plink user@host “/etc/rc.d/init.d/service_name restart”

The last command will simply restart the server, and will also require that a password be entered:

plink user@host “shutdown -r now”

Any of the above listed commands can be created as a shortcut on your desktop for easy access…


Related Posts

2 Comments »

  • sap said:

    Hi i am a big fan of your site, i read about plink how to use plink for tunneling with putty or can u please tell me if any server is there to use with putty for tunneling for free.

  • Rohan (author) said:

    Thankyou Saptarshi. I ill soon post a tutorial for that.

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

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

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.