Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

A GUI program over SSH says it cannot open the display

ErrorGtk-WARNING **: cannot open display: localhost:10.0

Short answer

ssh must forward X11 and the remote sshd must allow it. Connect with ssh -X, confirm sshd_config on the server has X11Forwarding yes, and make sure nothing in your shell startup files overwrites DISPLAY. ssh sets DISPLAY itself, and a hand-set value breaks the forwarded one.

  • Applies to OpenSSH 9, Ubuntu 22.04 and 24.04, Jetson Linux, Raspberry Pi OS
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Log in again with X11 forwarding asked for and verbose output on, then print DISPLAY on the remote side. A forwarded session shows a value with a display number above zero, such as localhost:10.0.

    ssh -v -X user@remote-host
    echo $DISPLAY
  2. 2Match what you see, then jump to its fix

    1. 1echo $DISPLAY prints an empty line on the remote host.The client did not ask for X11 forwardingFix
    2. 2ssh -v shows the request being made, yet DISPLAY stays empty on the remote host.The server's sshd does not allow X11 forwardingFix
    3. 3ssh -v shows forwarding set up, but DISPLAY holds a different value, such as :0, once the shell is ready.A startup file overwrites DISPLAYFix

What does the error look like?

  • Gtk-WARNING **: cannot open display: localhost:10.0
  • cannot open display:

Cause 1 of 3

The client did not ask for X11 forwarding

1Check

ForwardX11 defaults to no, so a plain ssh login forwards nothing. Check whether you used -X (or -Y) and whether your ssh config sets ForwardX11 for that host.

grep -n -i forwardx11 ~/.ssh/config

2Fix

Connect with -X, or set it for the host in your ssh config. Use -Y only if a program fails under the default untrusted mode.

ssh -X user@remote-host

# ~/.ssh/config
Host remote-host
    ForwardX11 yes

3Verify

DISPLAY is now set in the remote shell.

echo $DISPLAY

Confirmed by man.openbsd.org

Did this fix it?

Cause 2 of 3

The server's sshd does not allow X11 forwarding

1Check

X11Forwarding in sshd_config defaults to no. Look at the server's config and any files it includes.

sudo grep -ri x11forwarding /etc/ssh/

2Fix

Set X11Forwarding to yes on the server and restart sshd. Leave X11UseLocalhost at its default of yes unless you know you need the wildcard address.

# /etc/ssh/sshd_config
X11Forwarding yes

sudo systemctl restart sshd

3Verify

Log out, log in again with ssh -X and print DISPLAY.

ssh -X user@remote-host
echo $DISPLAY

Confirmed by man.openbsd.org

Did this fix it?

Cause 3 of 3

A startup file overwrites DISPLAY

1Check

The ssh manual says the user should not set DISPLAY by hand, because ssh points it at a proxy X server on the remote host. Search your startup files for an export.

grep -n DISPLAY ~/.bashrc ~/.profile ~/.bash_profile ~/.zshrc 2>/dev/null

2Fix

Remove the line that exports DISPLAY from the remote account's startup files, then log in again so ssh sets it.

# delete or comment out lines such as:
# export DISPLAY=:0

3Verify

After a fresh login with -X, DISPLAY shows localhost and a number above zero.

ssh -X user@remote-host 'echo $DISPLAY'

Confirmed by man.openbsd.org

Did this fix it?

How do I stop it coming back?

  • Use ssh -X only for the machines that need GUI tools, and prefer a plain terminal workflow elsewhere.
  • Never export DISPLAY in startup files of an account you reach over ssh.
  • Keep sshd_config under change control so X11Forwarding does not flip back after an upgrade.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.