7.13. Executing Commands Without Opening a Remote Shell

You have a single command to run on the remote machine, and you think it would be nice to be able to just run it without logging in and opening a remote shell, running the command, and then logging out. After all, is it not true that laziness is a virtue for network admins?

And, you shall have what you want because OpenSSH can do this. This example shows how to restart Postfix:

	$ ssh mailadmin@limberger.alrac.net sudo /etc/init.d/postfix restart

This shows how to open a quick game of Kpoker, which requires X Windows:

	$ ssh -X 192.168.1.10 /usr/games/kpoker

You'll be asked for a password, but you'll still save one whole step.

You have to use sudo when you need root privileges with this command, not su, because you can't use su without first opening a remote shell. This is also a handy way to script remote commands.

And yes, laziness is a virtue, if it leads to increased efficiency and streamlined methods of getting jobs done.