How to enable X11 forwarding for remote access
Environment
Linux/macOS/Windows with X11 server
OpenSSH client
X11 applications
Issue
When trying to run X11 applications on remote systems, encountered error message
username@slogin-01:~$ xclock Error: Can't open display:
Resolution
Enable X11 forwarding in SSH client when connecting to the remote system.
Enable X11 Forwarding
Note
X11 forwarding must be enabled when connecting to the remote system via SSH. Please disconnect your current SSH session and reconnect after applying the changes.
X11 forwarding can be enabled ad-hoc at command-line or persistently by modifying SSH client config.
One-time Connection
Use -X flag when connecting via SSH
ssh -X username@hpcname.ust.hk
Persistent Configuration
Add X11 forwarding settings to your SSH config file
Create or edit
~/.ssh/configmkdir -p ~/.ssh chmod 700 ~/.ssh nano ~/.ssh/config
Add the following configuration
Host hpcname.ust.hk ForwardX11 yes ForwardX11Trusted yesSet proper permissions
chmod 600 ~/.ssh/config
Verify X11 Connection
Test the connection by running a simple X11 application
Warning
Ensure you have an X11 server installed and running on your local machine
Linux: Usually pre-installed (xorg)
macOS: Install XQuartz
Windows: Install VcXsrv or Xming
xclock
Or check the DISPLAY environment variable
echo $DISPLAY
Root Cause
X11 forwarding requires client support, which is disabled by default.