Xhost command not working

Hi,
I am not able to work with the command xhost. I need to open the same machine (not any other remote machine) in UI mode. How can I open this using xhost? I am using Putty to login to this machine.

I am simply writing the command as --> xhost +
There is an error displayed --> xhost: unable to open display "".
Please help on this.

Thanks in advance!

I think - in this case - you don't need xhost at all.

What you need is:

  • X server on Windows (e.g. Xming)
  • Configure the particular putty connection (Enable X11 forwarding)
  • Ensure that the remote server permits X11 forwarding ( X11Forwarding yes in sshd_config )

Hi Thanks junior-helper,
I am using VNC on Windows to access a remote RedHat machine, but I receive an error "The connection was refused by the host computer". Th parameter X11 Forwarding is set to yes on the Redhat machine. But still this does not work, any further help on this?

Yes.

I see at least 3 potential problems:

  • You don't have an appropriate VNC server installed on your remote host
  • You have the VNC server, but it's not configured
  • VNC server is configured and up&running, but the firewall blocks incoming connections.

I don't know which of the points mentioned applies to your environment.

Below you will find instructions on how to configure the VNC server on the remote host (installation tested on RH6.4, access tested with Remmina):

# install vnc server
[root@host ~]# yum install tigervnc-server

# configure vnc server
[root@host ~]# vi  /etc/sysconfig/vncservers

VNCSERVERS="2:someuser"
VNCSERVERARGS[2]="-geometry 800x600"

Add above two lines in the /etc/sysconfig/vncservers file (it will configure display :2 for user someuser).

# switch to user someuser
[root@host ~]# su - someuser

# set vnc password for user someuser
[someuser@host ~]$ vncpasswd 
Password:
Verify:
[someuser@host ~]$ exit

# start vnc server
[root@host ~]# service vncserver start
Starting VNC server: 2:someuser 
New 'host:2 (someuser)' desktop is host:2

Creating default startup script /home/someuser/.vnc/xstartup
Starting applications specified in /home/someuser/.vnc/xstartup
Log file is /home/someuser/.vnc/host:2.log

                                                           [  OK  ]
# check if vnc server is listening on the appropriate port
[root@host ~]# netstat -ant | grep 5902
tcp        0      0 0.0.0.0:5902                0.0.0.0:*                   LISTEN      
[root@host ~]#
# it might be necessary to modify iptables to allow incoming connections on port 5902

Important note: This is an insecure setup (unencrypted connection).

Anyhow, with a minor change in /etc/sysconfig/vncservers ( VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost" ), it is possible to configure vnc server to only accept vnc connections from localhost, or through a ssh tunnel respectively. On Windows, the connection will not work anymore with a VNC client only (no ssh support?), but it should work in combination with Putty.