Since 2016 · 50,000+ customers · ★ 5.0 on Google Live chatWhatsAppTelegramOpen a ticket
Get started
Linux

How to Configure X11 Forwarding on CentOS 7, AlmaLinux and Rocky Linux

How to configure X11 forwarding on CentOS guide by 99RDP

X11 forwarding lets you run a graphical program on a remote Linux server and see its window on your own computer, tunnelled securely through SSH. You don't need a full desktop or VNC on the server, just a couple of small packages and one SSH setting. This guide covers the server setup on CentOS 7 and on its successors (AlmaLinux, Rocky Linux and RHEL 8, 9 and 10), and the client side on Linux, macOS and Windows.

Quick answerOn the server, install xorg-x11-xauth, make sure /etc/ssh/sshd_config has X11Forwarding yes, restart sshd, then connect with ssh -X user@server and run a GUI program.

A note on CentOS 7

CentOS 7 reached end of life on 30 June 2024. It gets no more security updates, and its default yum mirrors are offline, so package installs fail unless you point the repos at vault.centos.org. The steps below still work on CentOS 7, but for any server that faces the internet, move to AlmaLinux or Rocky Linux. The configuration is the same there; only yum becomes dnf.

Step 1: Install xauth on the server

SSH needs the xauth program on the server to set up the forwarded display. Without it you'll see "X11 forwarding request failed".

# CentOS 7
sudo yum install -y xorg-x11-xauth

# AlmaLinux / Rocky Linux / RHEL 8, 9, 10
sudo dnf install -y xorg-x11-xauth

For a quick test, also install a small X program. On CentOS 7, sudo yum install -y xorg-x11-apps gives you xclock and xeyes. On newer releases, any GUI program you actually need (for example gedit or firefox) works as a test.

You do not need to install a desktop environment or an X server on the server. The X server runs on your own computer.

sshd -T output showing x11forwarding yes and x11uselocalhost yes on an AlmaLinux server
Confirming the X11 settings in sshd

Step 2: Enable X11 forwarding in sshd

Open the SSH server config:

sudo vi /etc/ssh/sshd_config

Make sure these lines are present and not commented out:

X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes

On CentOS, X11Forwarding yes is usually on already. Check the result and restart SSH:

sudo sshd -t && sudo systemctl restart sshd
sudo sshd -T | grep -i x11

sshd -t checks the file for errors before the restart, so a typo can't lock you out.

X servers for Windows to use X11 forwarding: MobaXterm, VcXsrv and WSLg
X11 on Windows

Step 3: Connect from your computer

From Linux

Your desktop already runs an X server (or XWayland), so just connect with -X:

ssh -X user@server-ip

Use -Y (trusted forwarding) only if a program fails with -X; it gives the remote program more access to your display.

From macOS

Install XQuartz from xquartz.org, log out and back in once, then use ssh -X user@server-ip from Terminal.

From Windows

  • MobaXterm: the easiest option. It includes an X server, and X11 forwarding is on by default for SSH sessions.
  • PuTTY + VcXsrv: start VcXsrv (XLaunch), then in PuTTY go to Connection → SSH → X11, tick Enable X11 forwarding and set the display to localhost:0.
  • Windows 11 with WSL: WSLg includes an X server, so ssh -X from a WSL terminal works without extra software.
Diagram of X11 forwarding: an app runs on the server and its window is drawn by the X server on your computer through SSH
How X11 forwarding works

Step 4: Verify that it works

After logging in, check the display variable:

echo $DISPLAY

It should print something like localhost:10.0. If it's empty, forwarding isn't active. Now start a program:

xclock &

A clock window should open on your own screen. The program runs on the server; only its window is drawn locally.

Troubleshooting

  • "X11 forwarding request failed on channel 0": xauth is missing, or IPv6 is disabled on the server. Install xorg-x11-xauth; if IPv6 is off, add AddressFamily inet to sshd_config and restart sshd.
  • "Can't open display" or empty $DISPLAY: you connected without -X, or your local X server (XQuartz, VcXsrv) isn't running.
  • Works as your user but not after sudo: root doesn't have your X cookie. Run sudo -E or copy it with xauth list and sudo xauth add ….
  • Very slow windows: X11 over the internet is chatty. Add compression with ssh -XC, or use a full remote desktop (xrdp or VNC) for heavy GUI apps.

Frequently asked questions

What is X11 forwarding?

It's an SSH feature that sends a remote program's graphical window to the X server on your local computer, encrypted inside the SSH connection.

Do I need a desktop environment on the server for X11 forwarding?

No. You only need xauth and the program you want to run. The X server runs on your own machine.

What's the difference between ssh -X and ssh -Y?

-X uses untrusted forwarding with X security restrictions; -Y is trusted and less restricted. Use -X unless a program doesn't work with it.

Is X11 forwarding still useful on Wayland desktops?

Yes. Wayland desktops run XWayland, which accepts forwarded X11 windows, so ssh -X keeps working.

Nishant Kumar, Sr. Server Engineer at 99RDP
Written byNishant KumarSr. Server Engineer, 99RDP. Part of the team that runs our servers and answers support.
Keep reading

More Linux guides

All Linux guides

Need a server for this?

✓ Setup in minutes✓ Full admin access✓ 7-day refund on new services