Centos – How to have the login screen through VNC in Oracle Linux

centosoracle-vm-servervnc

Basically what I am looking for is similar feature like RDP on Windows. I should be able to view the login screen through VNC Viewer. Even if server is restarted I should still be able to access it through VNC Viewer. Currently someone has to first obtain the console through OVM (these are all VMs), login and only then is it possible to remote through VNC Viewer.
I know this question has been asked here previously [ref1] [ref2] also here but so far I have been unsuccessful in my attempts. Can anyone provide a detailed guide on how to go about achieving this?

  • OS: Oracle Linux 5
  • VNC rpm : vnc-server-4.1.2-14.el5_6.6

Update 1 – VNC at User Level

Ok so I followed everything listed here

  • Logged in to the server through PuTTY using root (because that's the acount I need to use for logging in through VNC).
  • Ran vncpasswd and set the VNC login password.
  • Saved the script as /etc/init.d/vncserver after changing the following parameters:
    • USER="root"
    • DISPLAY="1"
  • Did chmod +x /etc/init.d/vncserver.
  • Did chkconfig --level 2345 vncserver on.
  • Did vi /root/.vnc/xstartup and uncommented the lines:
    unset SESSION_MANAGER
    exec /etc/X11/xinit/xinitrc
    

    and changed last line from twm & to startx & (since I'm using GNOME).

  • Restarted the server.

Now I could successfully remote to the server through VNC Viewer. This works even if server is restarted. However, it bypasses the lock screen and does not prompt for password. For this I had to set up a password through System > Preferences > Remote Desktop.
Important Note: As @slm described below, this method provides VNC access at user level. Meaning you can create multiple users and provide them VNC access separately. Each user will have a unique desktop. This wasn't exactly what I was looking for though!

Update 2 – VNC at System Level, like RDP on Windows

After implementing @slm's solution, I realised that this was what I actually had in mind when I asked this question. I followed exactly what he said. It's a lot simpler! Couple of things I would like to add:

  • I didn't need to install x11vnc. I used only the vnc rpm that was installed by default.
  • /etc/X11/xorg.conf file was missing. To create it I did the following: (Source)

    • As root run: Xorg :1 -configure. This will create the file /root/xorg.conf.new
    • cp /root/xorg.conf.new /etc/X11/xorg.conf

I followed rest of the instructions. Restarted gdm and Voila! It worked! I was able to see the login screen through VNC Viewer, exactly like RDP on Windows. It worked even after server restart. Great!

Best Answer

To add to @Timo's answer there sounds like there are 3 ways to setup VNC access.

  1. At the user level (that's what you're using now)
  2. At the system level
  3. At the Host level (when running inside of a VM) - this is Timo's suggestion

NOTE: This tutorial shows how to do #1, it's titled: How to install VNC server on CentOS 6.

If you think for a second #3 is actually just another form of #1 & #2, depending on where you provide access to the desktop. At the user level (#1) or at the system level, (#2).

So I think what you want is actually #2. To get this type of setup working there are basically 2 methods that I'm aware of.

x11vnc

You can install the package x11vnc and then use this to gain access to the current X11 session on a remote system. It's generally in most of the Red Hat based distro repos so I won't cover installation, but once installed you'd ssh into a system that you want to access the console display (:0.0), and manually run it like so:

$ x11vnc -nopw -display :0.0

There are methods for making this more permanent so that it just runs as part of the session. One such method is discussed in this blog post, titled: x11vnc on CentOS5 with GDM.

X11 + vnc

The second method is to install a module/driver into X11 so that you can connect to any running X11 desktop. The one I'm familiar with is called vnc. This driver needs to be installed into the host system's X setup so that you can access the system's login manager. I'm not sure what it is on Oracle (most likely it's GDM - GNOME Display Manager) since it derives from RHEL.

The good news is that if you'e installed the package vnc-server you already have the X11 driver installed. Simply add this to your host system's X11 setup.

First you'll need to add this line to your xorg.conf's Module section:

# /etc/X11/xorg.conf
Section "Module"
  Load "vnc"
EndSection

Next you'll need to add several lines to this same files Screen section:

Option "SecurityTypes" "VncAuth"
Option "UserPasswdVerifier" "VncAuth"
Option "PasswordFile" "/root/.vnc/passwd"

Last setup a password for this connection, using the tool vncpasswd, then restart X.

References

Related Question