Log In | Register | March 2, 2024


Linux - June 16, 2012

Access remote systems using ssh and VNC.

Access remote systems using SSH

SSH allows you to remotely access computers and or servers as long as the service is up and running. The basic usage for the command is as follows.

ssh user@hostname

The hostname could be either an IP Address or a domain name accessible from the computer you’re trying to ssh from.

There is also an alternative method for logging in using the SSH command which would be to define the username with a -l flag.

ssh -l user hostname

The default port for SSH is 22, but you could also have your sshd service listening on a different port if you configured it to do so. If your SSH server is listening on port 2222 we could easily login by defining the port in our ssh command.

ssh -p 2222 user@hostname

Another useful flag that you can use is the -X flag. Which then enables X11 forwarding allowing you to run GUI programs over the net on your local machine.

ssh -X user@hostname

Lastly, another useful flag available with ssh is the -v flag which triggers the verbose mode. This would allow you to see the progress for your connection as well as any issues you may encounter along the way.

ssh -v user@hostname

Access remote systems using VNC

When connecting to a remote system via VNC it is important to make sure that the tigervnc-server package is installed and running on that remote system. If not, please follow the steps below to configure the remote system.

Installing tigervnc-server

In order to install tigervnc-server you simply type the command

yum install tigervnc-server

After the install is complete you will then find a new configuration file available to you at /etc/sysconfig/vncservers.

Next step is to edit the configuration file.

vi /etc/sysconfig/vncservers

Now we need to add 2 lines. The first line will be to define the user and port number for our VNC connection. The second line is for defining the connection directives such as screen resolution or remote connections. By default you will see that the last 2 lines in the configuration file are commented out that way we can use it as a reference. So now lets add our 2 lines for our user.

VNCSERVERARGS[2]=”-geometry 800x600”

The above 2 lines define our user and port number as well as the default resolution when we connect. The number 2 actually maps to the port number 5902. We could change that to 3, 4 or anything for the matter and the port would reflect using that number.

You could also set it up so that only your localhost can connect via VNC by adding the -localhost flag as such.

VNCSERVERARGS[2]=”-geometry 800x600 -localhost”

Now to set our VNC password.

Now that you have your configuration file changes in place, you need to set the password for the VNC connection for your defined user. Above we used the user frank. Login as that user and then open a terminal and proceed to type the following.


You will then be prompted for a password you would like to set. This password is unrelated to the actual user account.

Starting the VNC Server

Now that we have all of our configurations set as well as our password, it is now time to start our service.

service vncserver start

To ensure that the service is automatically started after reboot you could run the following:

chkconfig vncserver on

Accessing the Remote VNC Server

Before we can access remote systems via VNC, we need to make sure we have the appropriate package installed.

yum install tigervnc

The above command will then install the program vncviewer which will allow you to connect to remote systems as such.

vncviewer hostname:2

You would replace hostname with either your host name or ip address. We used the number 2 since it it was we configured on our server earlier.

If you set it up that only your localhost can connect to your VNC server, then you could run vncviewer over a SSH tunnel as such.

vncviewer -via user@hostname localhost:2

You would replace user with your ssh user name and host name with either your host name or ip address.

Post By: | FavoriteLoadingAdd to favorites


RHCSA Certification Study Guide | DevBlog.co
Monday, June 25, 2012

[...] Access remote systems using ssh and VNC [...]

Leave a Comment

Need Help? Ask a Question

Ask anything you want from how to questions to debug. We're here to help.

You Must Be Logged In To Post A Question.

Log In or Register