The following simple guide helps you to setup the VNC server on RHEL 7 / CentOS 7 machines, VNC help to share the desktop with the other machines which have a client installed.
VNC server and client are not installed, by default. You need to setup the vnc server manually.
Prerequisites
Before installing the VNC server, you would need install Gnome desktop using YUM command.
READ: Install Gnome Desktop on CentOS 7 / RHEL 7
Install VNC Server
VNC server package is available on base operating system repository. So, you can install the tigervnc server and X11 fonts packages using the YUM command.
yum install -y tigervnc-server xorg-x11-fonts-Type1
Configure VNC Server
Copy the VNC server configuration file to /etc/systemd/system/ for configuring the system service. While copying, you can mention which port it should listen.
By default VNC server listens on 5900, but if you setup port-offset for VNC; we can run a service on a sub-port of the default port 5900.
For example, if we mention port 5, the desktop will be accessible on 5905. You can connect the VNC server by specifying ipaddress:sub-port (192.168.2.109:5 or 192.168.2.109:5905)
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:5.service
Edit the copied file.
vi /etc/systemd/system/vncserver@:5.service
At the end of the file, you will find the lines like below.
[Unit] Description=Remote desktop service (VNC) After=syslog.target network.target [Service] Type=forking # Clean any existing files in /tmp/.X11-unix environment ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' ExecStart=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i" PIDFile=/home/<USER>/.vnc/%H%i.pid ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' [Install] WantedBy=multi-user.target
Replace <USER>
with your real user, in my case, i replaced with a user called raj
.
[Unit] Description=Remote desktop service (VNC) After=syslog.target network.target [Service] Type=forking # Clean any existing files in /tmp/.X11-unix environment ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' ExecStart=/sbin/runuser -l raj -c "/usr/bin/vncserver %i" PIDFile=/home/raj/.vnc/%H%i.pid ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :' [Install] WantedBy=multi-user.target
Firewall
Add firewall rules to allow the VNC connection. The following rule is set as per the port-offset mentioned in the previous step.
firewall-cmd --permanent --add-port=5905/tcp firewall-cmd --reload
Start VNC Server
Start VNC server after switching to raj.
[raj@server ~]$ vncserver
Set the password.
You will require a password to access your desktops. Password: Verify: xauth: file /home/raj/.Xauthority does not exist New 'localhost.localdomain:1 (raj)' desktop is server.itzgeek.com:1 Creating default startup script /home/raj/.vnc/xstartup Starting applications specified in /home/raj/.vnc/xstartup Log file is /home/raj/.vnc/server.itzgeek.com:1.log
Enable VNC Server
Switch to the root user.
su -
Reload the systemctl daemon as root.
systemctl daemon-reload
Start the VNC service as root.
systemctl start vncserver@:5.service
Enable it on system startup as root.
systemctl enable vncserver@:5.service
Access VNC Desktop
Open up a VNC viewer from Windows machine and enter a remote desktop address.
ipaddress:5905
ipaddress:5
Have you figured out a way to set the geometry (screen size) ?
As per the manual, geometry value can be specified in the service file it self, just have to append the value in the line ExecStart=/sbin/runuser -l raj -c “/usr/bin/vncserver %i”. It did not work for me, so i manually changed the disaplay after taking the VNC.
hi Raj,
i tried using your instructions, but wasnt able to get it connected. this is what i get when i run journalctl -xn. any help would be appreciated.
Unit vncserver@:5.service has begun starting up.
Aug 26 20:56:32 localhost.localdomain runuser[14370]: runuser: user does not exist
Aug 26 20:56:32 localhost.localdomain systemd[1]: vncserver@:5.service: control process exited, code=exited status=1
Aug 26 20:56:32 localhost.localdomain systemd[1]: Failed to start Remote desktop service (VNC).
— Subject: Unit vncserver@:5.service has failed
— Defined-By: systemd
— Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Hi Ahmed,
Please find the following line in “vncserver@:5.service” file,
ExecStart=/sbin/runuser -l raj -c “/usr/bin/vncserver %i -geometry 1280×1024”
replace “raj” with your “real user”
Thanks heaps Raj,
that worked,
Hi
Thanks for that guide, it’s pretty usefull ! But i wonder if we can also install or pass with RDP on 7 ? I know XRDP can be install on Centos6.5, but on 7 was it too..? There’s the rpm Epel that needed , but don’t know if it’s already over the dvd iso of 7…
Or maybe it’s for a futur install guide..
thanks again
Because of the corporate Firewall rules we have in place; I can not use any group of ports on the 5900 range. so I wonder if you can provide me information on how to configure my redhat server in order to SSH tunneling and use tigervnc with a localhost port instead ?. You help will be highly appreciate it.
Thank you very much.
Dear Diego,
Pls visit the following url. This is the one you are looking for. I have tested, works great
http://crl.ucsd.edu/handbook/vnc/
Hi Johnny,
New how to made for xrdp on CentOS 7. Use the following link.
https://www.itzgeek.com/how-tos/linux/centos-how-tos/install-xrdp-on-centos-7-rhel-7.html
Many thanks for great tutorial!
When I connect to VNC server, I get black screen (of seemingly correct resolution) with a small grey rectangle in top left corner, saying
“Accept clipboard from viewers”
“Send clipboard to viewers”
“Send primary selection to viewers”
And I cannot do anything, i. e. no matter where I click, there is no reaction.
(I am using vncviewer from UltraVNC package on Windows.)
Now it is working.. after a forced reboot.
I had another problem that gnome-shell was taking 2-6GB per process with my system running into swap.
Maybe there was another error.. anyway, it is working now.
I also followed the xrdp tutorial. Thanks for that too. 🙂
I am a bit surprised though that unlike the windows usage (vnc: current session, rdp: new session) on linux, both create new (parallel) sessions. And those are then reused for each following connection through same channel. a bit different handling.
Also, unlike Windows, VNC is faster than RDP (using tight compression it is like working on a local machine).
But then, I have not used a GUI for Linux for the past years, only doing a little administration through the shell here and there. 🙂
Hi
Almost related, but will it be possible to put a vnc tutorial for Mint 17 also ? Tigervnc might be working fine on..
But with Mint, the vino-preference doesn’t work, supposed to be included, but…
We have always configured remote access to VNC through xinetd. Doing so allows for more security controls on who can remotely access the system. With CentOS 6 and prior the xinetd configuration provides the “gdm greeter” login screen and you can have any number of concurrent instances of the gnome desktop subject to xinetd configuration. That’s to say you don’t create a separate config for each user. So all around it is a better configuration (more secure access, Linux login controls and multiple sessions with one config) albeit a little more complex to set up.
So that preamble all leads up to a question. Do you know of anyone that has posted the xinetd setup for a CentOS 7 remote vnc desktop? I’m trying to work through it, but I can see it’s going to be a challenge without some tips.
Thanks!
Dear Brent,
As requested, we have made new how-to. Hope this helps.
Take a look here, https://www.itzgeek.com/how-tos/linux/centos-how-tos/remote-login-with-gdm-and-vnc-on-centos-7-rhel-7-configure-vnc-on-xinetd-with-xdmcp-centos-7-rhel-7.html#axzz3HHvjSwPP
Follow the guide but at the last few steps (Starting the vnc service as root I get command not found…
Start VNC from normal user
Raj, How did you manually change the display size??
Hello Ray
Trying to do the last step (starting the service) but I get this error
[root@server mike]# systemctl start vncserver@:1.service
Job for vncserver@:1.service failed. See ‘systemctl status vncserver@:1.service’ and ‘journalctl -xn’ for details.
[root@server mike]# systemctl -l status vncserver@:1.service
vncserver@:1.service – Remote desktop service (VNC)
Loaded: loaded (/etc/systemd/system/vncserver@:1.service; disabled)
Active: failed (Result: exit-code) since Thu 2015-02-26 17:16:14 CET; 2min 54s ago
Process: 10481 ExecStart=/sbin/runuser -l mike -c /usr/bin/vncserver %i -geometry 1280×1024 (code=exited, status=98)
Process: 10477 ExecStartPre=/bin/sh -c /usr/bin/vncserver -kill %i > /dev/null 2>&1 || : (code=exited, status=0/SUCCESS)
Feb 26 17:16:14 server.localdomain systemd[1]: Starting Remote desktop service (VNC)…
Feb 26 17:16:14 server.localdomain systemd[1]: vncserver@:1.service: control process exited, code=exited status=98
Feb 26 17:16:14 server.localdomain systemd[1]: Failed to start Remote desktop service (VNC).
Feb 26 17:16:14 server.localdomain systemd[1]: Unit vncserver@:1.service entered failed state
What can I do about this?
Thank your very much.
Try to use vncserver@5
how to remove all the packages to redo the setup
Hi Raj,
Once logged in using VNC client, the session is different from the actual system. Is there a way to get the same session ?
USE VINO
http://www.techotopia.com/index.php/Remote_Access_to_the_CentOS_Desktop
The instructions worked well. Thanks!
this does not work
Tutorial has been updated, it has been checked
localhost.internal systemd[1]: Failed to start Remote desktop service (VNC).
— Subject: Unit vncserver@:1.service has failed
Remove this file if there is no X server
: A VNC server is already running as :1
.internal:1 is taken because of /tmp/.X11-unix/X1
pam_unix(runuser-l:session): session opened for user root by (uid=0)
hi, i failed to start the vnc server any ideas?
vncserver@:5.service – Remote desktop service (VNC)
Loaded: error (Reason: Invalid argument)
Active: inactive (dead)
Dec 09 12:11:43 localhost.localdomain systemd[1]: vncserver@:5.service has more than one ExecStart setting, which is only allowed for Type=oneshot services. Refusing.
Dec 09 12:11:51 localhost.localdomain systemd[1]: vncserver@:5.service has more than one ExecStart setting, which is only allowed for Type=oneshot services. Refusing.
Dec 09 12:11:53 localhost.localdomain systemd[1]: vncserver@:5.service has more than one ExecStart setting, which is only allowed for Type=oneshot services. Refusing.
Dec 09 12:11:59 localhost.localdomain systemd[1]: vncserver@:5.service has more than one ExecStart setting, which is only allowed for Type=oneshot services. Refusing.
[root@localhost ~]# chkconfig vncserver on
error reading information on service vncserver: No such file or directory
I am trying to setup remote desktop on CentOS 7, its work for me… Cheerful
[How To Install and Configure VNC Remote Access for the GNOME Desktop on CentOS 7](https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-remote-access-for-the-gnome-desktop-on-centos-7?comment=35734)
thanks for sharing, i configure its working but the issue is i can view user desktop i access desktop what user is doing i cant see, it work like Remote login not as VNC like redhat 6 and below. can you help me how i get full access of user desktop and view what he is doing