When I work at the office, I occasionally need to log into the desktop of a Linux box located remotely at the Data Center.
I could use VNC, but it is slow on this network, and unless I install tightVNC, the remote machine has to be already logged in order to access it.
My laptop is also Linux, so setting up remote X11 over SSH was actually quite simple.
Here’s a step-by-step how-to.
**Please note**
The following is case sensitive.
Pay attention to the different file names.
This assumes the ssh server is installed and running.
If your distro does not have an ssh server, consult its documentation for installing and enabling it.
On the remote ssh server machine, edit /etc/ssh/ssh_config.
Uncomment or add the following lines and make them match this:
ForwardAgent yes
ForwardX11 yes
ForwardX11Trusted yes
Still on the remote ssh server machine, edit /etc/ssh/sshd_config.
Uncomment or add the following lines and make them match this:
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes
After editing and saving the above config files, restart sshd on the remote server, or simply reboot it.
From a terminal on the local ssh client machine, enter the following:
This command will create an instance of the X server at tty12:
X :12.0 vt12 2>&1 >/dev/null &
It will also switch you to the as yet unused tty12.
Press <control+alt+(F1-F7)> to get back to the terminal you launched the command from.
This command will open the ssh session to the remote server and activate X forwarding:
xterm -display :12.0 -e ssh -X -C your_user@remote_server &
Now switch to the terminal at tty12 by pressing the following keys:
<control+alt+F12>
You should see a password prompt, enter the appropriate password for the user.
If it is the first time connecting, enter yes to accept the ssh key.
Once the user is logged in, enter the command to start the desktop environment for the remote machine.
startkde
xfce-session
gnome-session
Your remote desktop environment should now come up on your local screen as if you were sitting at the physical machine.
There are a couple of minor caveats:
-You may need to set the screen resolution to be appropriate to the local monitor
-There will be a terminal window open with X11 messages scrolling in it. Do not close it or press <control+c> in it
as it will kill your X session and you will have to start it again.
-If you created and started the remote X11 session from a terminal in your local X11 session, closing this local terminal window will kill the remote session on tty12.
-I create the X instance at startup in /etc/rc.d/rc.local and then log into it when needed from a tty terminal.
-This allows my local X11 session to be completely detached from the remote one.
When you are done, simply logout of the remote desktop environment as you normally would.
You may also logout of the ssh session if you wish, or keep it active for later use.