In the blog, I would like to exploit the ways to connect the remote server and get graphic UIs.
Useful Commands:
- Check used ports:
netstat -tulpn
sudo ss -lntp
- Get Xtigervnc’s process id or check if VNC server is active:
pgrep Xtigervnc
ss -tulpn | egrep -i 'vnc|590'
Install Destkop on Ubuntu
XFCE and GNOME are both desktop environments for Linux which are suitable for VNC servers to connect, while XFCE is lighter with low resource systems.
-
Xfce4
sudo apt install xfce4 xfce4-goodies
-
Ubuntu-Gnome
1
2
3
sudo apt install ubuntu-gnome-desktop
sudo systemctl enable gdm
sudo systemctl start gdm
VNC4server
1
2
3
vncserver -list
vncserver :1
vncserver -kill :1
TightVNC or TigerVNC
Tutorial
Recommand TigerVNC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
sudo apt install xfce4 xfce4-goodies # Install Xfce Desktop
sudo apt install tigervnc-standalone-server tigervnc-common # install TigerVNC
# sudo apt install tigervnc-standalone-server tigervnc-xorg-extension tigervnc-viewer
sudo apt install tigervncserver # Install TightVNC
vncserver # set password
vncserver -kill :1 # kill the first server for configuration
vi ~/.vnc/xstartup
> #!/bin/bash
> xrdb $HOME/.Xresources
> startxfce4 &
sudo chmod +x ~/.vnc/xstartup # set priviledge for the startup file
vncserver # restart vncserver
ssh -L 5901:127.0.0.1:5901 -C -N -l <username on remote server> <remote server ip> # set a secure tunnel on local machine
#Finally use local vnc connection like Go of Finder in Mac by 127.0.0.1:5901
# After that, we can also set a systemctl for vncserver for personal convenience.
Next Step:
- Must we use ssh tunnel?
-
No, we can use
vncserver -localhost no :X
to build a new vncserver and ssh tunnel is not needed. The reason we need a ssh tunnel is because the vncserver will only listen to the localhost network interface card. -
There is a problem. When we build two vncservers, the second one will display gray view without any desktops.
-
-
Can we change Desktop style?
- Yes: by editing
~/.vnc/xstartup
.
- Yes: by editing
Problem Recordings
As to the Ubuntu16.04, we will meet with grey screen problem. Currently, I am not sure about the reason but get the solution from the link. Basically, if we change the xstartup
file under the ~/.vnc/
and we can use a basic desktop.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
x-window-manager &
gnome-panel &
gnome-settings-daemon &
metacity &
nautilus &
Teamviewer
Teamviewer will let all users in the same remote machine to share a remote partner id. So everyone who wants to use teamviewer to connect the remote server will get the access to the owner of the teamviewer.
It is very dangerous since the priviledge is broken.
Tutorial works well for GUI Ubuntu. Community Link
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
dpkg -i <teamviewer.deb> # install teamviewer
sudo apt -f install # install required dependencies
teamviewer --deamon start
teamviewer info
teamviewer --passwd <newPassword> # Password need to be set before connect the remote server
teamviewer info # get the ClientID
sudo teamviewer --daemon stop
sudo rm -f /opt/teamviewer9/config/global.conf
sudo teamviewer --daemon start
teamviewer help # list all available commands
teamviewer info # show TeamViewer ID
teamviewer passwd # set password
teamviewer setup # assign device to account
For new users to use VNCserver
On the server side:
- Initialize your own vncserver
1
2
vncserver # set password
vncserver -kill :1 # kill the first server for configuration
- setup your own
xstartup
1
2
3
4
5
6
7
8
9
10
vi ~/.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
- Restart the vncserver
1
2
sudo chmod +x ~/.vnc/xstartup # set priviledge for the startup file
vncserver # restart vncserver
On your own computer:
- build a ssh channel
1
ssh -p <server port> -L 5901:127.0.0.1:5901 -C -N -l <username on remote server> <remote server ip> # set a secure tunnel on local machine
- Use your personal vnc client to connect the server on
vnc://127.0.0.1:5901
.
Some tips:
- I found that one account can build the same desktop once, even including the physical monitor I use connecting to the machine. Otherwise, it cannot build the new desktop (deadlock and sigkilled) or just shows the background color without any icons and menu.
- The possible reason is that when one desktop shows the folders in one vnc session, the resources are occupied and other desktops cannot get access to them which can just show blank background.