Remotely Connecting to CentOS 7 via VNC
Overview
A VNC (Virtual Network Computing) is a graphical desktop sharing system that can remotely control another computer.
On your local computer, please install a supported VNC Client:
On macOS, you can use the built-in Screen Sharing program, or can use a cross-platform app like RealVNC.
On Linux, you can choose from many options, includingÂ
vinagre
,Âkrdc
, RealVNC, or TightVNC.
Using Windows
If you don’t already have PuTTY installed, please follow the link SSH to Instance using Windows.
Also, download a supported VNC Client, if you haven’t already. In this example, we will use TightVNC.
Connect to your server through PuTTY and open the terminal window.
First, create user accounts. These accounts will remotely connect to our CentOS 7 server.
Use the following command to add user accounts and set their passwords. Repeat to add as many users as needed.sudo useradd -c "User newuser Configured for VNC Access" newuser1 sudo passwd newuser1
Install GNOME Desktop.
sudo yum groupinstall "GNOME Desktop" sudo reboot
Following the reboot, reconnect to your server.
Install TigerVNC for a VNC server.
sudo yum install tigervnc-server
Configure VNC Service for your clients/accounts.
Open the service unit file for each client.
Press Insert on your keyboard. Then replace and input the following commands under
[Service]
:To save and exit, press the ESC key then type :wq.
Note: Remember to change the username in the commands fromnewuser1
.
Additionally, if you have more than one user, you would need to replicate steps 5-7 for each user.
For example, if I have a second user (newuser2), I would do the following:Reload and boot all VNC servers. The
enable
function will start the VNC server at boot time.Repeat line 2 for all clients, remembering the replace the port number.
Configure the firewall
Note: If you have more than one user, also include their port in the firewall rules, like in the following:
Now, we will open a new PuTTY session and change a few of the settings.
First, ensure the checkbox for Enable X11 forwarding in the left menu under SSH - X11 is checked.On the directory on the left-hand side of PuTTY, expand SSH and click on Tunnels.
In Source Port, enter:5900
In Destination, enter:your_serverip:5901
oryour_serverip:<5900+port_number>
- Where the port number corresponds to the user you desire. The port number should match the one used in Steps 5-7.
- Whereyour_serverip
, in this case, should be the IP address and not the Floating IP.
Click Add, then Open.In the terminal, switch to your desired user and set VNC server password.
Note, the display port listed in the outcome of line 2 may differ than the port number itself.
Open your VNC viewer client and connect to
localhost:5900
You should see something like the following:
After the initial setup, every reboot will require users to start at Step 10 to reconnect to the VNC server. This includes creating the SSH tunnel to the desired port. Please visit the following section to save the SSH tunnel information to PuTTY: Setup SSH Tunnel Information in PuTTY
Using Mac or Linux
If you haven’t already, please download a supported VNC Client. In this example, we will use TightVNC.
Connect to your server and open the terminal window.
Instructions on how to connect to your server through SSH can be found here:
SSH to Instance using Mac and LinuxFirst, create user accounts. These accounts will remotely connect to our CentOS 7 server.
Use the following command to add user accounts and set their passwords. Repeat to add as many users as needed.Install GNOME Desktop.
Following the reboot, reconnect to your server.
Install TigerVNC
Configure VNC Service for your clients/accounts.
Open the service unit file for each client.
Press Insert on your keyboard. Then replace and input the following commands under
[Service]
:To save and exit, press the ESC key then type :wq.
Note: Remember to change the username in the commands fromnewuser1
.
Additionally, if you have more than one user, you would need to replicate steps 5-7 for each user.
For example, if I have a second user (newuser2), I would do the following:Reload and boot all VNC servers. The
enable
function will start the VNC server at boot time.Repeat line 2 for all clients, remembering the replace the port number.
Configure the firewall
Note: If you have more than one user, also include their port in the firewall rules, like in the following:
Switch to your desired user and set VNC server password.
Note, the display port listed in the outcome of line 2 may differ than the port number itself.
Enter the following connection information to use SSH tunneling
Replace
newuser1
andyour_server_ip
with the appropriate username and server IP address, not Floating IP address.Open your VNC client and connect to
localhost:5900
. Once connected, you should see something like the following:
After the initial setup, every reboot will require users to start at Step 10 to reconnect to the VNC server. This includes creating the SSH tunnel to the desired port.
Setup SSH Tunnel Information in PuTTY
Open a new PuTTY sesssion and enter in the Host Name information, but do not click
Open
yet.Under
Saved Sessions
, label what you want the server and SSH information to be known as.On the directory on the left-hand side of PuTTY, expand
SSH
and click onX11
. Check the box to Enable X11 forwarding.Return back to the default main page, by clicking on
Session
in the directory.
ClickSave
.On the directory on the left-hand side of PuTTY, expand
SSH
and click onTunnels
.
In Source Port, enter:5900
In Destination, enter:your_serverip:5901
oryour_serverip:<5900+port_number>
- Where the port number corresponds to the user you desire. The port number should match the one used in Steps 5-7.
- Whereyour_serverip
, in this case, should be the IP address and not the Floating IP.
Click Add.Return back to the default main page, by clicking on
Session
in the directory.
ClickSave
once again.The next time you reboot the instance and reopen PuTTY, load the saved session. If you click on
SSH
→Tunnels
, you should find the added SSH port forwarding. You should also find that the X11 forwarding was also saved. Then clickOpen
.
Â
Â
Â