Post

Remote to Linux Desktop

Remote to Linux Desktop

Description: Remote access Linux Desktop GUI


X Forwarding

We have to first enable X forwarding. We SSH to the remote Linux computer with -XC where X is the X service and C allows data compression.

1
ssh -XC kyuubi@192.168.0.40

Install xauth on the remote machine.

1
2
sudo apt update
sudo apt install -y xauth

Check if X11Forwarding is yes in /etc/ssh/sshd_config.

1
2
$ cat /etc/ssh/sshd_config | grep X11Forwarding
X11Forwarding yes

Restart OpenSSH service.

1
sudo systemctl restart sshd

Confirm X forwarding is enabled.

1
2
$ echo $DISPLAY
localhost:10.0

Linux Desktop Forwarding

let's install the following dependencies

1
2
sudo touch /dev/fuse
sudo apt install -y xfce4 xfce4-goodies gnome-icon-theme libcanberra-gtk-module

Run the following command on the remote Linux computer while we are still ssh -X in.

1
xfce4-session

The forwarded desktop will show up on our local computer.
Opening X applications from the forwarded desktop is fine. But we were not able to open terminal to run commands.

Linux Desktop Forwading via VNC

To install the VNC server, we will install tightvncserver on the remote Linux computer.

1
sudo apt install -y tightvncserver

Then we could start a virtual desktop with an id of 1.

1
vncserver :1 -geometry 1920x1080 -depth 24

We could then connect to the remote Linux desktop using VNC client software on our local computer.

Remmina is installed by default on my local Ubuntu 20.04 LTS. Here we just have to input the remote Linux computer IP address with the VNC virtual desktop id, and press Enter. Next, disconnect VNC and kill the virtual desktop.

1
vncserver -kill :1

we will install lxde on the remote Linux computer.

1
sudo apt install -y lxde

We will modify the ~/.vnc/xstartup by adding /usr/bin/startlxde to it. The modified file will look like this.

1
2
3
4
5
6
7
8
9
10
11
$ cat ~/.vnc/xstartup
#!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
/etc/X11/Xsession
/usr/bin/startlxde

Finally, restart VNC server

1
vncserver :1 -geometry 1920x1080 -depth 24

There are some inconvenience that copy and paste text between the local computer and the remote desktop does not work. To fix this problem, again, we disconnect the VNC connection and kill the virtual desktop.

1
vncserver -kill :1

We will install autocutsel on the remote Linux computer.

1
sudo apt install -y autocutsel

We will modify the ~/.vnc/xstartup by adding autocutsel -fork to it. The modified file will look like this.

1
2
3
4
5
6
7
8
9
10
11
12
$ cat ~/.vnc/xstartup
#!/bin/sh

xrdb $HOME/.Xresources
xsetroot -solid grey
autocutsel -fork
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
/etc/X11/Xsession
/usr/bin/startlxde

Finally, restart VNC server.

1
$ vncserver :1 -geometry 1920x1080 -depth 24
This post is licensed under CC BY 4.0 by the author.