How to resolve X11 authentication error

Last updated: 2024-12-05
Solution under review

Environment

  • Linux/macOS/Windows with X11 server

  • OpenSSH client with X11 forwarding enabled

  • X11 applications

Issue

  • When running X11 applications after enabling X11 forwarding, encountered authentication error

    username@hpcname:~$ firefox
    X11 connection rejected because of wrong authentication
    Error: cannot open display: localhost:10.0
    

Resolution

  • Set the XAUTHORITY environment variable to point to the correct xauth file

    export XAUTHORITY="$HOME/.Xauthority"
    
  • Launch the application again

    username@hpcname:~$ firefox
    

Root Cause

X11 forwarding requires proper authentication between the client and server.

While some applications defaults to look for xauth file at ~/.Xauthority, some X11 applications may require setting the XAUTHORITY environment variable explicitly.