Do you have a Remote Ubuntu 16.04 server?
I know you all usually connect your Ubuntu server through shell commands.
Have you ever thought of accessing your remote Ubuntu Server through GUI?
Some of you might know about accessing GUI. But some of you might not know about that.
I am going to show you how to connect your Ubuntu GUI with your local system.
The Ubuntu remote server has been accessed by everyone through the command line.
If you have any Linux distribution operating system, you can use your terminal to connect with Ubuntu directly and perform operations through command line.
Most of us don't usually think of using remote Ubuntu GUI look likes due to the expertise in the command line usages.
Some people are not expert in commands and they will like to use the Ubuntu through GUI.
Here I am going to show you, how to connect your Ubuntu 16.04 GUI and how to use it yours on your machine.
I have added additional points to fix the grey screen issue later in this article.
- Ubuntu 16.04 server with sudo nonroot user with the initial server setup as mentioned here.
- Local Desktop with VNC application installed. you can use Real VNC, Tight VNC or Ultra VNC for Windows desktop with Putty or without putty.
If you are MAC user, you can use the built-in screen sharing program or you can use third-party cross-platform applications like RealVNC.
Linux users can use Real VNC and Tight VNC.
What is VNC?
VNC stands for Virtual network Computing.
The applications help you to connect to a remote system's GUI to your local system through the network and work on it.
We are going to install TightVNC application for our Ubuntu Machine.
Step 1: Installing Graphical Desktop Environment and TightVNC.
We are going to install Graphical Desktop Environment and packages of TightVNC from official Ubuntu Repository.
$ sudo apt install xfce4 xfce4-goodies tightvncserver
The Ubuntu VNC server will be installed. To finalize the installation just type vncserver in the command line to enter.
The setup will ask you to setup a password.
Enter the password and confirm it. Then you will be asked to enter the view only password.
The people who logins with view only password will only see the desktop and they cannot access the desktop through keyboard or mouse.
You can use view only password to demonstrate something to others.
This is not necessary.
Installing VNC server installs all the files and your next step is to setup VNC server.
Step 2: Configuring Ubuntu VNC server.
We have to tell the VNC about what command to run when it starts up.
These details are stored in the configuration file xstartup under the .vnc folder in the home directory.
The file was created when you installed and configured the VNC. But we need to change some commands for xfce.
Before editing the file, we have to stop the VNC from running on port number 5091.
First, stop TightVNC in Ubuntu by executing the following command.
$ vncserver -kill :1
You will get the following output with different PID number.
$ Output Killing Xtightvnc process ID 18965
We are now going to make some changes in the xstartup file.
Before that, we have to take backup of the xstartup file.
$ mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
After that, create a new Xstartup file using the nano editor.
$ nano ~/.vnc/xstartup
Past the below command in that file. So, it will take effect whenever you start or restart the VNC server.
~/.vnc/xstartup #!/bin/bash xrdb $HOME/.Xresources startxfce4 &
The first line xrdb $HOME/.Xresources tells the VNC's GUI framework to read the server user's Xresource file.
The second line starts the Xfce.
The Xresource file has the setting such as themes, cursor themes, terminal color and font rendering.
The second file has all the necessary graphical software to manage the server.
For VNC to execute this new startup file, we have to grant the privileges to execute the file.
$ sudo chmod +x ~/.vnc/xstartup
Next, restart the server.
Now, you will get the following output.
New 'X' desktop is your_server_name.com:1
Starting applications specified in /home/username/.vnc/xstartup
Log file is /home/username/.vnc/liniverse.com:1.log
Steps 3: Testing the VNC
You have to check your VNC. You have to connect to the remote server using SSH connection and forward the connection to the localhost connection.
ssh -L 5901:127.0.0.1:5901 -N -f -l username server_ip_address
Replace the username with the system sudo username and server IP address.
If you are using Windows, install TightVNC and Putty.
Now make a connection through SSH.
In putty look at the SSH Tunnel Settings. Add the port number 5091 and remote host as Localhost:5091 there.
After that, come to session and save the settings.
Enter the IP to connect. Log in to the server and start the VNC.
After that Go to the Tight VNC viewer. Enter the Remote host as Localhost::5091.
Then Click on open. After that, you can see the GUI of your remote Ubuntu Server.
If you see any gray screen on Tight VNC viewer Ubuntu desktop, Just add the following line in your ~/.vnc/xstartup file.
Open ~/.vnc/xstartup file
$ nano ~/.vnc/xstartup
Add the lines in the file.
#!/bin/sh def export XKL_XMODMAP_DISABLE=1 unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS gnome-panel & gnome-settings-daemon & metacity & nautilus & gnome-terminal &
Save and exit.
Install GNOM using the following command.
$ apt-get install ubuntu-gnome-desktop -y
Restart Ubuntu server and connect the Remote Ubuntu Server through SSH.
Now open VNC and connect. The desktop will open.
Step 4: Creating VNC Service File
Here we are going to Make VNC server as systemd server so that it can start, stop and restart.
Let us a create a systemd file in /etc/systemd/system/vncserver@.service for VNC server using nano.
$ sudo nano /etc/systemd/system/vncserver@.service
Copy the below code and paste it in the file.
Make sure to replace the username with the your user name.
/etc/systemd/system/vncserver@.service [Unit] Description=Start TightVNC server at startup After=syslog.target network.target [Service] Type=forking User=sammy PAMName=login PIDFile=/home/sammy/.vnc/%H:%i.pid ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1 ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :%i ExecStop=/usr/bin/vncserver -kill :%i [Install] WantedBy=multi-user.target
Save and close the file.
Now reload the daemon to let the system know the existence of the file.
$ sudo systemctl daemon-reload
Enable the unit file.
$ sudo systemctl enable firstname.lastname@example.org
Stop the VNC server if it is still running.
$ vncserver -kill :1
Now start the unit like you start the systemd file.
$ sudo systemctl status vncserver@1
If it started correctly, you would get the following output.
Output email@example.com - TightVNC server on Ubuntu 16.04 Loaded: loaded (/etc/systemd/system/vncserver@.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2016-04-25 03:21:34 EDT; 6s ago Process: 2924 ExecStop=/usr/bin/vncserver -kill :%i (code=exited, status=0/SUCCESS) ... systemd: Starting TightVNC server on Ubuntu 16.04... systemd: pam_unix(login:session): session opened for user finid by (uid=0) systemd: pam_unix(login:session): session opened for user finid by (uid=0) systemd: Started TightVNC server on Ubuntu 16.04.
In this article, You have learned how to create the desktop GUI environment for you Ubuntu server and connect it to your local system using TightVNC.
You also learned Ubuntu desktop sharing with windows using Putty.
You can perform some more advanced tasks with the GUI.
People who are not expert in command line interface can easily use this option to connect and use their Ubuntu System.