How to forward X over SSH to run graphics applications remotely?
X11 forwarding needs to be enabled on both the client side and the server side.
On the client side, the -X
(capital X) option to ssh
enables X11 forwarding, and you can make this the default (for all connections or for a specific connection) with ForwardX11 yes
in ~/.ssh/config
.
On the server side, X11Forwarding yes
must be specified in /etc/ssh/sshd_config
. Note that the default is no forwarding (some distributions turn it on in their default /etc/ssh/sshd_config
), and that the user cannot override this setting.
The xauth
program must be installed on the server side. If there are any X11 programs there, it's very likely that xauth
will be there. In the unlikely case xauth
was installed in a nonstandard location, it can be called through ~/.ssh/rc
(on the server!).
Note that you do not need to set any environment variables on the server. DISPLAY
and XAUTHORITY
will automatically be set to their proper values. If you run ssh and DISPLAY
is not set, it means ssh is not forwarding the X11 connection.
To confirm that ssh is forwarding X11, check for a line containing Requesting X11 forwarding
in the output of ssh -v -X
. Note that the server won't reply either way, a security precaution of hiding details from potential attackers.
forwarding x11 by SSH.NET c# library
I found the solution:
SSHInstance = new SshClient(HostOrIP, Port, Username, Password);
SSHInstance.Connect();
streamSSH = SSHInstance.CreateShellStream(ShellID, 1, 0, 0, 0, 2000000);
ForwardedPortRemote forwardedPortRemote = new ForwardedPortRemote(6000 +X11ServerDisplay, HostOrIP, 6000 + X11LocalDisplay);
SSHInstance.AddForwardedPort(forwardedPortRemote);
forwardedPortRemote.Start();
SSH compression for X11 forwarding
X11 graphics take up a lot of bandwidth. If your remote host is some distance away (i.e. not on the LAN), then you'll probably suffer sluggishness in your exported X11 applications.
I'm not sure about SSH compression. Performance may depend on other factors, such as CPU performance. From the ssh
man page:
-C Requests compression of all data (including stdin, stdout,
stderr, and data for forwarded X11 and TCP connections). The
compression algorithm is the same used by gzip(1), and the
“level” can be controlled by the CompressionLevel option for pro‐
tocol version 1. Compression is desirable on modem lines and
other slow connections, but will only slow down things on fast
networks. The default value can be set on a host-by-host basis
in the configuration files; see the Compression option.
Here are some other workarounds you can use to make things faster:
- Instead of interacting with the GUI using X11 forwarding, consider something else that has better optimization/compression, such as VNC or NX/FreeNX.
- Use the terminal version of emacs instead of the GUI version.
SSH to NetBSD 8.2 guest with X11 gives X11 forwarding request failed on channel 0
X11 forwarding is disabled by default both in the ssh
client and in the sshd
server. The setting that controls it in the client is called ForwardX11
, and the setting in the server is called X11Forwarding
.
When connecting from the Ubuntu machine to the NetBSD machine using ssh
, the following configuration files are being used:
- On the
ssh
client (Ubuntu machine)~/.ssh/config
/etc/ssh/ssh_config
- On the
sshd
server (NetBSD machine)/etc/ssh/sshd_config
With the ssh(1)
client, however, you could just use the -X
switch instead of editing any of the client configuration files. In fact, I would highly recommend using the -X
switch over enabling X11 forwarding for all hosts (i.e. in a Host *
block like I'm showing below).
If you do want to edit the ssh
client configuration, the ssh_config(5)
settings are the ones you already noted:
Host *
ForwardX11 yes
XauthLocation /usr/bin/xauth
The default for XauthLocation
is already /usr/bin/xauth
on Ubuntu, so there should be no need to specify it, unless you have another xauth
program installed in another location and you want to use it with ssh
.
The sshd(8)
server on the NetBSD machine also has to allow X11 forwarding. These sshd_config(5)
settings are the ones you still need to change:
X11Forwarding yes
XAuthLocation /usr/X11R6/bin/xauth
Again, the default for XAuthLocation
is already /usr/X11R6/bin/xauth
on NetBSD 8.2, so there should be no need to specify it.
After changing the sshd_config
settings, you also need to restart the sshd
service (as the root user):
service sshd restart
Related Topics
How to Align the Columns of a Space Separated Table in Bash
Linux Process in Background - "Stopped" in Jobs
Truncating the First 100Mb of a File in Linux
How to Execute Mips Assembly Programs on an X86 Linux
Find and Replace a Particular Term in Multiple Files
What Is the *Nix Command to View a User's Default Login Shell
Command Line Arduino Compiling and Uploading
Redirect Standard Input Dynamically in a Bash Script
Trace of Executed Programs Called by a Bash Script
Accurately Calculating CPU Utilization in Linux Using /Proc/Stat
Howto Prepare Qtcreator for Linux Driver & Kernel Development
How to Calculate the Mean of a Column
What Does "/Dev/Null" Mean at the End of Shell Commands
How to Set a Global Nofile Limit to Avoid "Many Open Files" Error