Software⏱️ 4 min read📅 2026-06-11

How to Fix: xauth error with ssh X Forwarding

Troubleshooting X Forwarding issues with SSH on Debian systems.

Quick Answer: Try setting the DISPLAY environment variable before running ssh -X, e.g. export DISPLAY=:0

The 'xauth error with ssh X Forwarding' issue affects users who are trying to establish an SSH connection with X forwarding enabled, but instead encounter an error message indicating that the display name is 'bad'. This error occurs when the xauth authority file cannot be created or updated correctly, preventing the X server from authenticating the client.

This issue can be frustrating because it prevents users from accessing graphical applications on remote servers. The good news is that this problem has a known solution, and we will walk you through the steps to fix it.

💡 Why You Are Getting This Error

  • The primary reason for this error is that the xauth authority file cannot be created or updated correctly due to an incorrect display name. When you run 'ssh -X remote-ip', the client tries to create a new xauth authority file in the user's home directory, but if the display name is not set correctly, the file cannot be created. This can happen if the DISPLAY environment variable is not set or if the xhost + command is not executed correctly.
  • Another possible cause of this error is that the remote server does not have the necessary X11 forwarding enabled. In some cases, the ssh client may not automatically enable X forwarding by default, and you need to explicitly add the -X option when connecting to a remote server.

🛠️ Step-by-Step Verified Fixes

Enabling xhost +

  1. Step 1: To fix this issue, first make sure that the DISPLAY environment variable is set correctly on your local machine. You can do this by running the command 'export DISPLAY=':0'. This sets the display name to ':0', which should match the default display name used by most X servers.
  2. Step 2: Next, execute the xhost + command on your local machine to allow any application to access the display. The syntax for this command is 'xhost +'. You may need to run this command as the root user or use sudo if you are not running as root.
  3. Step 3: After executing the xhost + command, try reconnecting to the remote server using the ssh -X option. If the issue persists, proceed to the next method.

Setting DISPLAY and updating xauth authority file

  1. Step 1: Another approach is to set the DISPLAY environment variable correctly on your local machine before running the ssh command. You can do this by adding the following options when connecting to the remote server: '-D :0 -X'. The '-D' option sets the display name to ':0', while the '-X' option enables X forwarding.
  2. Step 2: After setting the DISPLAY environment variable, try updating the xauth authority file manually. You can do this by running the command 'xauth -f /root/.Xauthority add :10.0'. Replace ':10.0' with the actual display name used by your remote server.

✨ Wrapping Up

To summarize, the 'xauth error with ssh X Forwarding' issue is usually caused by an incorrect display name or a missing xhost + command. By enabling xhost + or setting the DISPLAY environment variable correctly and updating the xauth authority file, you should be able to resolve this problem and access graphical applications on remote servers successfully.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions