Software⏱️ 2 min read📅 2026-05-31

How to Fix: How do I fix a "cannot open display" error when opening an X program after ssh'ing with X11 forwarding enabled?

Cannot open display error when opening X program after ssh with X11 forwarding enabled.

Quick Answer: Enable X11 forwarding on the Ubuntu VM and set the DISPLAY environment variable before running the application.

The 'cannot open display' error occurs when the X server is not properly configured to work with SSH. This can be due to several reasons, including issues with the DISPLAY environment variable or problems with the X11 forwarding mechanism.

🔍 Why This Happens

  • When you enable X11 forwarding with SSH, the remote server's DISPLAY environment variable is not properly set. This causes the local application to be unable to open a display.

✅ Best Solutions to Fix It

Method 1: Enable Local X11 Forwarding

  1. Step 1: Open the SSH client settings and enable local X11 forwarding.

Method 2: Set DISPLAY Environment Variable

  1. Step 1: Run the command `export DISPLAY=:0` before launching the X11 application.

✨ Wrapping Up

By following these steps, you should be able to resolve the 'cannot open display' error and successfully run X11 applications on your remote server.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions