X-Forwarding

Let's assume that you have an X application on a remote machine that you need to run, and you want it to display on the X-server installed on your local machine. One way to run this remote application is to use X11-Forwarding. This guide explains how to setup X11-Forwarding on your machine. From the perspective of SSH, the remote machine is the server and your local machine is the client. From the perspective of X, the program on the remote machine is the X client, and X server runs on your local machine.

Installation
Your server most probably doesn't have X11 server installed or enabled. To achieve this:

It will pull and the rest of necessary packages.

Server Setup
X11Forwarding needs to be enabled on the sshd server. Do this by making the following edit: (Please be sure to edit the file sshd_config not ssh_config !)

After you make these changes, you will need to let sshd reload its configuration so the changes will be accepted:

Don't forget to log out and log in to the server for this change to take effect.

Client Setup
The client does not need any extra configuration. In order to connect to the server and use port forwarding, issue the following command:

The above will work from Apple's X11 running under 10.3 - Panther.

Under 10.4 - Tiger - use:

Also verify that X is running without the -nolisten tcp option.

-X vs -Y
is also known as secure X11-forwarding: it's secure, i.e., the server(running sshd) won't be able to spy on the client (key-logging etc...). is also known as insecure X11-forwarding: it's not secure but it can run more applications

Also, you may wish to use compression to speed things up.

-or-

Verify the DISPLAY
Now verify that the DISPLAY variable points to the display created by sshd (normally localhost:10.0):

If it points to the display of the connecting client machine, you need to manually set it:

Start Working
You should then be able to start any X application on the remote machine and have it display on your local machine. For example,

should display a new xterm window on the screen of the local machine.

No xauth data
If you get this warning:

Warning: No xauth data; using fake authentication data for X11 forwarding.

Add this to the end of

This is needed as ssh defaults XAuthLocation to while on Gentoo it is supposed to be

Another possible remedy: check your environment variable $HOME on the client. If not correctly set xauth obviously cannot find some of its data (probably the Authority file $HOME/.Xauthority). This can happen for instance in a script where $HOME has been assigned to another value.

Using after su or sudo
After doing su or sudo to root (or other user) Xforwarding should stop working, it's necessary to define and  variables (for example):

BadAtom? BadWindow?
If you get the BadAtom error like this:

X Error of failed request: BadAtom (invalid Atom parameter) Major opcode of failed request: 20 (X_GetProperty) Atom id in failed request: 0x6e Serial number of failed request: 20 Current serial number in output stream: 20

or a BadWindow error like this:

The program 'gtk-demo' received an X Window System error. This probably reflects a bug in the program. The error was 'BadWindow (invalid Window parameter)'. (Details: serial 3555 error_code 3 request_code 38 minor_code 0) (Note to programmers: normally, X errors are reported asynchronously;   that is, you will receive the error a while after causing it.    To debug your program, run it with the --sync command line    option to change this behavior. You can then get a meaningful    backtrace from your debugger if you break on the gdk_x_error function.)

Try adding:

to the or  on the machine that you ssh from, under the hostname or IP of the machine where the program runs.

Like this:

Please note that recent openssh implementations (>=4.4 at the very least) have changed their behaviour regarding the -X and -Y options. As most X applications know nothing about the XSECURITY extension it is required to use the -Y option to run them. Ssh won't tell you anything different from the above cases but if you get badwindow errors try with -Y. In these same versions the ForwardX11Trusted option seems to be gone as sshd complains about it and refuses to start.

Forwarding Automatically
If you wish to use X-forwarding without the -X argument, edit your or  and add an entry.