Skip to Main Content
Linux Security Cookbook
book

Linux Security Cookbook

by Daniel J. Barrett, Richard E. Silverman, Robert G. Byrnes
June 2003
Intermediate to advanced content levelIntermediate to advanced
336 pages
8h 54m
English
O'Reilly Media, Inc.
Content preview from Linux Security Cookbook

6.2. Invoking Remote Programs

Problem

You want to invoke a program on a remote machine over a secure network connection.

Solution

For noninteractive commands:

$ ssh -l remoteuser remotehost uptime

For interactive programs, add the -t option:

$ ssh -t -l remoteuser remotehost vi

For X Window applications, add the -X option to enable X forwarding. Also add the -f option to background the program after authentication, and to redirect standard input from /dev/null to avoid dangling connections.

$ ssh -X -f -l remoteuser remotehost xterm

Discussion

For noninteractive commands, simply append the remote program invocation to the end of the ssh command line. After authentication, ssh will run the program remotely and exit. It will not establish a login session.

For interactive commands that run in your existing terminal window, such as a terminal-based text editor or game, supply the -t option to force ssh to allocate a pseudo-tty. Otherwise the remote program can get confused or refuse to run:

$ ssh server.example.com emacs -nw
emacs: standard input is not a tty
$ ssh server.example.com /usr/games/nethack
NetHack (gettty): Invalid argument
NetHack (settty): Invalid argument Terminal must backspace.

If your program is an X application, use the -X option to enable X forwarding. This forces the connection between the X client and X server—normally insecure—to pass through the SSH connection, protecting the data.

$ ssh -X -f server.example.com xterm

If X forwarding fails, make sure that your remote ...

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 Administration Cookbook

Linux Administration Cookbook

Adam K. Dean

Publisher Resources

ISBN: 0596003919Errata Page