Skip to Main Content
Linux Server Security, Second Edition
book

Linux Server Security, Second Edition

by Michael D. Bauer
January 2005
Intermediate to advanced content levelIntermediate to advanced
544 pages
23h 44m
English
O'Reilly Media, Inc.
Content preview from Linux Server Security, Second Edition
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
138
|
Chapter 4: Secure Remote Administration
Using SSH to Execute Remote Commands
Now it’s time to take a step back from all this PK voodoo to discuss a simple feature
of SSH that is especially important for scripting: remote commands. So far we’ve
been using the command ssh strictly for remote shell sessions. However, this is
merely its default behavior; if we invoke ssh with a command line as its last argu-
ment(s), SSH will execute that command line rather than a shell on the remote host.
For example, suppose I want to take a quick peek at my remote system’s log (see
Example 4-7).
In Example 4-7, the host zippy will send back the contents of its /var/log/messages file
to my local console. (Note that output has been piped to a local
more process.)
Two caveats are in order here. First, running remote commands that require subse-
quent user interaction is tricky and should be avoided—with the exception of shells,
ssh works best when triggering processes that don’t require user input. Also, all
authentication rules still apply: if you would normally be prompted for a password
or passphrase, you still will. Therefore, if using SSH from a cron job or in other non-
interactive contexts, make sure you’re either using a passphrase-less key or that the
key you are using is first loaded into
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Linux: Powerful Server Administration

Linux: Powerful Server Administration

Uday Sawant, Oliver Pelz, Jonathan Hobson, William Leemans
Linux Server Hacks

Linux Server Hacks

Rob Flickenger
Linux Server Hacks, Volume Two

Linux Server Hacks, Volume Two

William von Hagen, Brian K. Jones

Publisher Resources

ISBN: 0596006705Supplemental ContentCatalog PageErrata