Skip to Content
Linux Networking Cookbook
book

Linux Networking Cookbook

by Carla Schroder
November 2007
Beginner
642 pages
15h 43m
English
O'Reilly Media, Inc.
Content preview from Linux Networking Cookbook

7.12. Tunneling X Windows Securely over SSH

Problem

OK, all of this command-line stuff is slick and easy, but you still want a nice graphical environment. Maybe you use graphical utilities to manage your headless servers. Maybe you want to access a remote workstation and have access to all of its applications. You know that X Windows has built-in networking abilities, but it sends all traffic in cleartext, which of course is unacceptably insecure, plus it's a pain to set up. What else can you do?

Solution

Tunneling X over SSH is simple, and requires no additional software.

First, make sure this line is in /etc/ssh/sshd_config on the remote machine:

	X11Forwarding yes

Then, connect to the server using the -X flag:

	[carla@windbag:~/.ssh]$ ssh -X stilton
	Enter passphrase for key '/home/carla/.ssh/id_rsa':
	Linux stilton 2.6.15-26-k7 #1 SMP PREEMPT Sun Jun 3 03:40:32 UTC 2007 i686 GNU/Linux
	Last login: Sat June 2 14:55:10 2007
	carla@stilton:~$

Now, you can run any of the X applications installed on the remote PC by starting them from the command line:

	carla@stilton:~$ ppracer

SSH sets up an X proxy on the SSH server, which you can see with this command:

	carla@stilton:~$ echo $DISPLAY
	localhost:10.0

Discussion

The X server runs with the offset specified in /etc/sshd.conf:

	X11DisplayOffset 10

This needs to be configured to avoid colliding with existing X sessions. Your regular local X session is: 0.0.

The remote system only needs to be powered on. You don't need any local users to be logged in, and ...

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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Linux Networking Cookbook

Linux Networking Cookbook

Gregory Boyce
Linux Security Cookbook

Linux Security Cookbook

Daniel J. Barrett, Richard E. Silverman, Robert G. Byrnes

Publisher Resources

ISBN: 9780596102487Errata Page