Software & AppsOperating SystemLinux

How To Fix “DISPLAY is not set” Error in xterm on Ubuntu

Ubuntu 20

In this article, we will delve into the issue of the “DISPLAY is not set” error in xterm on Ubuntu. This error typically occurs when you’re trying to run xterm or other GUI-based programs from a terminal session that isn’t properly configured to communicate with the X11 server.

Quick Answer

To fix the "DISPLAY is not set" error in xterm on Ubuntu, you need to ensure that X11 forwarding is enabled in the SSH configuration, use the correct flags when connecting via SSH, install the xauth program if necessary, and set the DISPLAY environment variable to the correct value.

Understanding the Problem

The X Window System, also known as X11, is a windowing system for bitmap displays, common on Unix-like operating systems. xterm is a terminal emulator for the X Window System. The “DISPLAY is not set” error usually indicates that the terminal session doesn’t know which X11 display to connect to.

The DISPLAY environment variable is used by the X Window System to establish a connection with the X server. If this variable isn’t set correctly, you’ll encounter the “DISPLAY is not set” error when trying to run xterm or other GUI-based applications.

Checking SSH Configuration

The first step in resolving this issue is to check the SSH configuration on the target machine. Open the /etc/ssh/sshd_config file and ensure that X11Forwarding is set to yes. This line allows the SSH server to forward X11 graphical data from the server to your local machine.

Also, verify that X11DisplayOffset is set to a value greater than 0, typically 10. This setting reserves display numbers for remote X11 connections.

Enabling X11 Forwarding

When connecting to the target machine via SSH, make sure to use the -X or -Y flag. These flags enable X11 forwarding. For example: ssh -X user@server.

Verifying X11 Forwarding

To verify that X11 forwarding is working correctly, start another SSH daemon on a different port for debugging purposes on the target machine. Run the command /usr/sbin/sshd -d -p 222. The -d flag is for debug mode, and -p 222 sets the port number.

Next, on the source machine, connect to the target machine with verbose output by running ssh -v -Y user@server -p 222. The -v flag is for verbose mode, -Y enables trusted X11 forwarding, and -p 222 specifies the port number.

Installing xauth

If you see an error message related to X11 forwarding, such as “No xauth program; cannot forward with spoofing”, it means the xauth program is missing on the target machine. The xauth program is used to edit and display the authorization information used in connecting to the X server.

You can install xauth on Ubuntu by running sudo apt-get install xauth.

Setting the DISPLAY Environment Variable

After connecting to the target machine via SSH, check the value of the DISPLAY environment variable by running echo $DISPLAY. It should display the address of the X11 server, such as localhost:10.0.

If the DISPLAY variable is not set, you can manually set it using the command export DISPLAY=:0. This command sets the DISPLAY variable to the default display.

Running xterm

Once you have verified that X11 forwarding is enabled, the xauth program is installed, and the DISPLAY variable is set correctly, you can try running xterm again. It should now work without the “DISPLAY is not set” error.

Conclusion

The “DISPLAY is not set” error in xterm on Ubuntu is a common issue that can be resolved by correctly setting up X11 forwarding and ensuring the DISPLAY environment variable is set correctly. By following the steps outlined in this article, you should be able to successfully run xterm and other GUI-based applications from your terminal session.

What is xterm?

xterm is a terminal emulator for the X Window System, commonly used on Unix-like operating systems.

Why am I getting the “DISPLAY is not set” error in xterm?

The "DISPLAY is not set" error occurs when the terminal session is not properly configured to communicate with the X11 server. This error usually happens when trying to run xterm or other GUI-based programs without the correct X11 display information.

How can I check the SSH configuration on the target machine?

You can check the SSH configuration by opening the /etc/ssh/sshd_config file and ensuring that X11Forwarding is set to yes and X11DisplayOffset is set to a value greater than 0, typically 10.

How do I enable X11 forwarding when connecting to the target machine via SSH?

To enable X11 forwarding, use the -X or -Y flag when connecting to the target machine via SSH. For example: ssh -X user@server.

What should I do if I see an error related to X11 forwarding?

If you see an error message related to X11 forwarding, such as "No xauth program; cannot forward with spoofing", it means the xauth program is missing on the target machine. You can install xauth on Ubuntu by running sudo apt-get install xauth.

How can I set the DISPLAY environment variable?

After connecting to the target machine via SSH, you can check the value of the DISPLAY environment variable by running echo $DISPLAY. If it is not set, you can manually set it using the command export DISPLAY=:0.

What should I do if I have followed all the steps but still get the “DISPLAY is not set” error?

If you have followed all the steps correctly and still encounter the error, it is possible that there might be another underlying issue. In such cases, it is recommended to seek further assistance or consult relevant forums and communities for troubleshooting.

Leave a Comment

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