I get a 'Can't open display: localhost:10.0' message when using the SSH protocol

You may see a ‘Can’t open display: localhost:10.0' error message when attempting to run an X application, such as Xterm, via an Xstart Session or an Xshell SSH session.

There are multiple reasons why you may be seeing this error. We’ll go over each of those reasons below and explain how to resolve them.

Error when manually designating DISPLAY

Unless you have a sufficient understanding of the ins and outs of the DISPLAY environment variable, you should not manually designate this setting.

This is a situation in which DISPLAY is explicitly set in the startup script in the user’s home directory. Which startup script is utilized (.bash_profile, .bashrc, .profile, .login, .cshrc, .zshrc, etc.) depends on the shell you are using.

Applying the user’s environment may be dependent on system startup scripts and user startup scripts, so you should refer to the shell’s help documentation (MAN).

Error when localhost is set incorrectly

Make sure that the localhost is set to 127.0.0.1 in the /etc/hosts file.

In rare instances, localhost may not be registered or it may be set to a different value. In this case, you need to edit the file with root priveleges.

# vi /etc/hosts ... 127.0.0.1 localhost ...

The SSH protocol uses a tunneling function, X11 forwarding, to run remote X applications through a secure SSH tunnel. At this time, the agreed upon value (Cookie) between the client and server is verified. After the SSH connection is made, this value is written to the .Xauthority file in the user’s home directory. By checking this cookie value, only authorized users can run X11 applications.

If there is an issue with writing this cookie value or if the recorded value cannot be read, the X11 forwarding may fail or you may see an error message.

There are several instance when the COOKIE may not be able to be processed.

  1. The cookie value is unable to be recorded without the xauth tool
    In this case, the xauth command is not found in the path or the package with the applicable file is not installed. If not found in the path, it needs to be set in the SSH configuration file, sshd_config. This case is quite rare.

    However, the situation where the SSH server is installed but xauth is not installed is quite common. You will need to install the package containing xauth using your Linux/UNIX installer.

    For Ubuntu:

    # apt install xauth


    For Redhat:

    # yum search xauth ... ================================= N/S matched: xauth ===================================== xorg-x11-xauth.x86_64 : X.Org X11 X authority utilities # yum install xorg-x11-xauth ...

     

  2. You are unable to access the .Xauthority file
    Verify that the access rights of the user’s home directory are correctly set and modify them if they are not.


    If the .Xauthority-c or .Xauthority-l files exist in the user’s home directory, delete them.
    Normally, these files should be automatically deleted after the session ends, but there are instances where they remain. If the files remain, you will be unable to write the correct information to the .Xauthority file.

     

  3. The user was changed with the su command
    If the user is changed with the su command, the DISPLAY environment variable may be properly relayed, but the Cookie value may not. When switching from one normal user to another normal user, the Cookie value will not be properly relayed.

    If you need to use an X application after switching users, you must know the previous user’s cookie value before switching.

     

Error when the SSH server cannot handle X11 forwarding

In rare instances, even if X11 forwarding is enabled in the SSH server’s settings, the X connection may fail, resulting in the ‘Can’t open display…' error message.

In this case, you should restart the ssdh daemon with the following command: