CentOS – Como conectar con escritorio remoto por VNC

Este es un mini howto que no tiene en cuenta las mil variables, es para ir por faena. Después de que configuramos un CentOS con escritorio remoto vamos a ver como nos podemos conectar sino estamos físicamente delante del equipo.

1. Comprobamos que tenemos los paquetes necesarios

# rpm -q vnc-server
# rpm -q vnc

Si es que no:

2. Instalamos

# yum install vnc-server vnc

3. Se requiere instalar las X y un escritorio, podemos verlo aqui.

Ahora, vendría la parte en la que configuraremos VNC Server. Ya digo que podéis montar la NASA: vpn, túnel ssh, …etc. Yo voy al grano en este howto 🙂

You will perform the following steps to configure your VNC server. Estos serían los pasos:

Create the VNC users accounts.
Edit the server configuration.
Set your users’ VNC passwords.
Confirm that the vncserver will start and stop cleanly.
Create and customize xstartup scripts.
Amend the iptables.
Start the VNC service.
Test each VNC user.
Additional optional enhancements

Daremos acceso únicamente al usuario root (con dos webos) por un único puerto y el iptables desactivado(crazy!). Ante todo seguridad.

4. Editamos /etc/sysconfig/vncservers y añadimos las líneas siguientes al final

VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 1024x768 "

Aquí estamos definiendo en VNCSERVERS las parejas de pantalla/usuario. El array de VNCSERVERARGS define la resolución para la pantalla/usuario deseado.

5. Configuramos el password VNC para nuestro usuario root(oh my god!)

# vncpasswd

esto creará un directorio ‘.vnc’ dentro de la home del user.

6. Ahora como root (ups, si ya estabamos como root) nos aseguramos que vncserver arranca y para sin problemas. Esto creará xstartup script

# /sbin/service   vncserver start
# /sbin/service   vncserver stop
# /sbin/chkconfig vncserver on

7. Editar ~/.vnc/xstartup para cada usuario, debería quedar así:

#!/bin/sh
# Add the following line to ensure you always have an xterm available.
( while true ; do xterm ; done ) &
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &

8. Si tenemos puertos cerrados deberemos configurar los puertos para poder aceptar conexiones VNC

[root@xen-221 sysconfig]# cat iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -i eth1 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp -m multiport --dports 5901:5903,6001:6003 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
[root@xen-221 sysconfig]#  
# /sbin/service iptables restart

9. Lanzamos el servicio

# /sbin/service vncserver start

10. Ahora desde un programa como vncviewer nos conectamos. Si hemos definido un sólo usuario el string de conexión sería

IP:5901

Links
http://wiki.centos.org/HowTos/VNC-Server
http://www.techotopia.com/index.php/Displaying_CentOS_Applications_Remotely_(X11_Forwarding)
http://www.ndchost.com/wiki/server-administration/centos5-vnc-x11

One thought on “CentOS – Como conectar con escritorio remoto por VNC

Leave a Reply

Your email address will not be published. Required fields are marked *