Tip #27: Automating Linux Admin From Windows Over SSH
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...
If you have any questions on today's tip, please leave a comment... Check back tomorrow for new tips...
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...
If you have any questions on today's tip, please leave a comment... Check back tomorrow for new tips...
1 Comments:
At 7/26/2006 5:37 PM, Anonymous said…
I use Plink & putty on client machines to get back to my box server etc, what would be cool is the exact reverse command line access to windows boxes via linux at the moment if I wish to remotely login I have to use a small windows hack to allow 2 simil users then rdesktop which is a command line RDP client then TSclient.
This allows me a full gui rich environment to shutdown windows or whatever but its no where near as easy as running a short cut that whacks out a single shell or bash command.
just musings, once again thanks for the tip its interesting to see different little work arounds one use we use Plink for is creating ssh tunnels to authentication servers.
Post a Comment
<< Home