Menu
Install and configure X11
“How the X Window System is built, where its config lives, and how to show programs on another screen safely.”
Every graphical Linux program, from a terminal window to a web browser, needs something that owns the screen, the keyboard and the mouse. For almost 40 years that something has been the X Window System, also called X11 or just X. It still runs on millions of machines, and its successor, Wayland, keeps it around for older apps.
You need X knowledge when a desktop won’t start, when the keyboard layout is wrong on the login screen, or when you want to run a program on a server and see its window on your laptop. The exam also loves the odd part of X: its idea of “client” and “server” looks backwards at first.
How X is built#
X is split into two halves that talk over the X protocol:
- The X server runs on the machine with the screen. It owns the graphics card, the monitor, the keyboard and the mouse. On Linux the X server program is Xorg (from the X.Org project). The command
Xis usually a link to it. - X clients are the programs:
xterm, Firefox, a file manager. They ask the server “draw this rectangle here” and the server sends them events like “a key was pressed”.
your laptop (has the screen) any machine
+----------------------------+ +-----------------+
| X server (Xorg) | <----> | X client |
| screen, keyboard, mouse | X | (xterm, gedit) |
+----------------------------+protocol+-----------------+That’s why it feels backwards: the server sits in front of you, and the clients can run anywhere, even on a machine in another building. X was built to be network transparent: a client doesn’t care whether its server is local or across the network.
On top of the bare X server, a desktop is made of more clients:
| Component | What it does | Examples |
|---|---|---|
| Display manager | The graphical login screen. Starts the X server and your session. | GDM (GNOME), SDDM (KDE), LightDM, XDM |
| Window manager | Draws borders and title bars, moves, resizes and stacks windows. | Mutter, KWin, Xfwm4, Openbox, i3 |
| Compositor | Blends windows into the final image (shadows, transparency). Often built into the window manager. | Mutter, KWin, picom |
| Desktop environment | The full package: window manager plus panels, file manager, settings, apps. | GNOME, KDE Plasma, Xfce |
| Toolkit | The library apps use to draw buttons and menus. | GTK, Qt |
Without a window manager, X still works, but windows have no borders and you can’t move them. Try it once and you’ll never forget what a window manager does.
The DISPLAY variable#
A client finds its server through the DISPLAY environment variable:
echo $DISPLAY:0
The format is host:display.screen:
| Part | Meaning | Default |
|---|---|---|
host | Machine running the X server. Empty means “this machine, through a local socket”. | local |
display | Which X server on that host. The first is 0, the next 1, and so on. | required |
screen | Which screen of that server (rare today). | 0 |
So :0, :0.0 and unix:0 all mean the first local display, and office-pc:0 means the first display on office-pc. A local server listens on a Unix socket called /tmp/.X11-unix/X0 for display 0. Over the network, display n uses TCP port 6000 + n, so display :1 is port 6001.
You can point a single program at another display without changing your shell:
DISPLAY=:1 xterm &
xterm -display :1 &Installing and starting X#
Most desktop installs already include Xorg. On a minimal system:
# Debian / Ubuntu
sudo apt install xorg
# RHEL / Fedora
sudo dnf install xorg-x11-server-Xorg xorg-x11-xinitTo see which version you have:
Xorg -versionX.Org X Server 1.21.1.7
X Protocol Version 11, Revision 0
There are two ways X gets started:
- A display manager (the usual way). It’s a systemd service, so
systemctl status display-managershows which one you have. Boot into the graphical target withsudo systemctl set-default graphical.target. On Debian, the chosen display manager is also written in/etc/X11/default-display-manager. - By hand from a text console with
startx. It’s a friendly wrapper aroundxinit, which starts the X server and then runs the clients listed in~/.xinitrc(or the system default/etc/X11/xinit/xinitrc). When the last line of that file exits, X stops.
xsetroot -solid steelblue
xterm &
exec xfce4-sessionYou can also start a bare second server with X :1 (or Xorg :1) and switch to it with Ctrl+Alt+F-keys. It’s an empty grey or black screen until a client connects.
Configuration files#
Modern Xorg detects your graphics card, monitors and input devices by itself, so most systems have no /etc/X11/xorg.conf at all. You only add configuration to change something the auto-detection got wrong.
| Path | What it is |
|---|---|
/etc/X11/xorg.conf | The classic single config file. Optional today. |
/etc/X11/xorg.conf.d/*.conf | Small snippets, read in name order. Your overrides go here. |
/usr/share/X11/xorg.conf.d/*.conf | Defaults shipped by packages (for example 40-libinput.conf). Don’t edit them, updates overwrite them. |
/var/log/Xorg.0.log | Log of display :0 when X runs as root. |
~/.local/share/xorg/Xorg.0.log | The same log when X runs as your user (“rootless” X, the default with GDM on many distros). |
The file is made of sections. Each one starts with Section "Name" and ends with EndSection:
| Section | Describes |
|---|---|
ServerLayout | Ties screens and input devices together. The top level. |
Files | Paths to fonts and modules. |
Module | Extra server modules to load. |
InputDevice | One specific keyboard or mouse (old style). |
InputClass | Rules that match all devices of a kind, for example “every keyboard”. |
Device | A graphics card and its driver. |
Monitor | A monitor and its supported modes. |
Screen | Joins one Device and one Monitor, sets color depth and resolutions. |
A small example that forces a driver and a resolution:
Section "Device"
Identifier "Card0"
Driver "modesetting"
EndSection
Section "Monitor"
Identifier "Monitor0"
EndSection
Section "Screen"
Identifier "Screen0"
Device "Card0"
Monitor "Monitor0"
DefaultDepth 24
SubSection "Display"
Depth 24
Modes "1920x1080" "1280x1024"
EndSubSection
EndSectionNeed a full starting file? Stop X first, then as root run Xorg -configure. It probes the hardware and writes /root/xorg.conf.new, which you can test with Xorg -config /root/xorg.conf.new before copying it to /etc/X11/xorg.conf.
Override one thing: the keyboard layout#
The exam’s favorite override is the keyboard. You don’t need a full xorg.conf for that, just one InputClass snippet:
Section "InputClass"
Identifier "system-keyboard"
MatchIsKeyboard "on"
Option "XkbLayout" "us,de"
Option "XkbModel" "pc105"
Option "XkbOptions" "grp:alt_shift_toggle"
EndSectionXkbLayout sets the layouts, XkbVariant picks a variant like dvorak, and XkbOptions adds extras: grp:alt_shift_toggle switches layout with Alt+Shift, and terminate:ctrl_alt_bksp lets Ctrl+Alt+Backspace kill a frozen X server.
You rarely write this file by hand. Each distro family has a tool:
# RHEL / Fedora (and other systemd distros): writes 00-keyboard.conf for you
sudo localectl set-x11-keymap de
localectl status System Locale: LANG=en_US.UTF-8
VC Keymap: de
X11 Layout: de
# Debian / Ubuntu: the layout lives in /etc/default/keyboard
sudo dpkg-reconfigure keyboard-configuration
grep XKB /etc/default/keyboardXKBMODEL="pc105"
XKBLAYOUT="de"
XKBVARIANT=""
XKBOPTIONS=""
To change the layout only for the running session, with no file at all, use setxkbmap:
setxkbmap de
setxkbmap -queryrules: evdev
model: pc105
layout: de
Troubleshooting with the logs#
When the screen stays black, read the X log. Every line starts with a marker:
| Marker | Meaning |
|---|---|
(EE) | Error |
(WW) | Warning |
(II) | Information |
(**) | Set in a config file |
(==) | Default value |
(--) | Probed (detected) |
(++) | Set on the command line |
grep -E '\((EE|WW)\)' /var/log/Xorg.0.log[ 12.418] (WW) Falling back to old probe method for fbdev
[ 12.512] (EE) Failed to load module "nvidia" (module does not exist, 0)
The X log is about the server. Errors from your session and the programs in it go to ~/.xsession-errors. The session scripts that display managers run (on Debian, /etc/X11/Xsession) send everything the clients print on stderr into that file. If your desktop logs in and drops you straight back to the login screen, look there first:
tail -n 20 ~/.xsession-errorsNewer GNOME and KDE sessions send this output to the systemd journal instead, so the file may be missing or old. Then try journalctl --user -b.
Who may connect: xhost and xauth#
Any client that can connect to your X server can read your keystrokes, take screenshots and draw over your windows. So X has two ways to decide who gets in.
xhost: allow by host or user#
xhost manages a list of allowed hosts. Run without arguments, it shows the current state:
xhostaccess control enabled, only authorized clients can connect
SI:localuser:amin
| Command | Effect |
|---|---|
xhost +192.168.1.50 | Allow every user on that host |
xhost -192.168.1.50 | Remove that host again |
xhost +si:localuser:bob | Allow local user bob (a “server interpreted” entry) |
xhost + | Turn access control off. Anyone can connect. |
xhost - | Turn access control back on |
Caution
xhost + with nothing after it opens your display to everyone who can reach it. Old tutorials use it as a quick fix. Don’t.
xauth: allow whoever has the cookie#
The better way is a secret token, the MIT-MAGIC-COOKIE-1. When X starts, the display manager creates a random cookie and stores it in ~/.Xauthority (or the file named in the XAUTHORITY variable). A client must present the matching cookie to connect. xauth manages those cookies:
xauth listlaptop/unix:0 MIT-MAGIC-COOKIE-1 5c2e0a9d1f8b4c37a1e6d2b9f04c8e11
To let another machine use your display, copy the cookie for it. This one-liner extracts the cookie for your display and merges it into your ~/.Xauthority on the remote host:
xauth extract - $DISPLAY | ssh amin@server xauth merge -Showing programs on a remote X server#
The modern way: SSH X11 forwarding#
SSH tunnels the X protocol through its encrypted connection and handles the cookie for you:
ssh -X amin@server
echo $DISPLAY
xclock &localhost:10.0
The clock runs on server but its window opens on your laptop. SSH created a fake display :10 on the server and forwards it back home. It needs X11Forwarding yes in the server’s /etc/ssh/sshd_config and the xauth program installed on the server.
ssh -Xtreats the remote programs as untrusted: they can’t snoop on your other windows. Some programs misbehave with it.ssh -Ygives them full, trusted access. Use it only with servers you trust.
The old way: plain X over the network#
Before SSH, you pointed DISPLAY straight at the other machine:
# on the laptop with the screen: allow the server
xhost +server.example.com
# on the server: send windows to the laptop
export DISPLAY=laptop.example.com:0
xclock &This only works if the X server listens on TCP port 6000, and current Xorg and display managers turn that off by default (-nolisten tcp). Everything, including your typing, would travel unencrypted. Know it for the exam, use SSH in real life.
Wayland, the successor#
Wayland is a newer display protocol that replaces X on most modern desktops. The big change: there’s no separate X server and window manager. The compositor (Mutter in GNOME, KWin in KDE, or Sway, Weston) is the display server, talking straight to the kernel’s graphics drivers.
| X11 | Wayland | |
|---|---|---|
| Display server | Xorg plus a separate window manager | The compositor does both |
| Apps can see other windows and keystrokes | Yes | No, each app is isolated |
| Network transparency | Built in | No; use RDP, VNC or app-level tools |
xhost, xauth, DISPLAY | Yes | No (WAYLAND_DISPLAY instead) |
| Old X apps | Native | Run through XWayland, a small X server inside the session |
Wayland is the default on Fedora, RHEL 8 and later, Debian 12 (GNOME) and Ubuntu 22.04 and later. RHEL 10 goes further and no longer ships the Xorg server at all, only XWayland. To see what you’re running:
echo $XDG_SESSION_TYPEwayland
On a GDM login screen you can still pick “GNOME on Xorg” from the gear menu where it’s installed. Admins can disable Wayland with WaylandEnable=false in the [daemon] section of /etc/gdm/custom.conf (RHEL/Fedora) or /etc/gdm3/custom.conf (Ubuntu; Debian uses /etc/gdm3/daemon.conf).
echo $DISPLAY often prints :0. That’s XWayland waiting for old X programs. Running xeyes and moving the mouse over a native Wayland window is a fun test: the eyes freeze, because X apps can’t see Wayland windows.Exam checklist#
- In X, the server is on the machine with the screen and keyboard; clients are the programs, local or remote.
DISPLAYishost:display.screen;:0is the first local display, and display n uses TCP port 6000 + n./etc/X11/xorg.confis optional; put small overrides in/etc/X11/xorg.conf.d/*.conf.Xorg -configurewritesxorg.conf.new.- Keyboard layout: an
InputClasssection withOption "XkbLayout"; tools arelocalectl set-x11-keymap,dpkg-reconfigure keyboard-configurationandsetxkbmap(session only). - Server problems:
/var/log/Xorg.0.log,(EE)errors. Session problems:~/.xsession-errors. xhostallows hosts or users (xhost +disables all control).xauthmanages MIT magic cookies in~/.Xauthority.ssh -X(untrusted) orssh -Y(trusted) forwards X securely; needsX11Forwarding yes.- Display managers (GDM, SDDM, LightDM, XDM) log you in; window managers (Mutter, KWin, Xfwm4) manage windows.
- Wayland: the compositor is the display server, no network transparency, X apps run through XWayland.
Answer these 3 questions to commit this byte to your learning path.
Reset. This byte isn't committed any more. Answer the questions again to commit it.
$ git commit -m "learn(lpic-106): Install and configure X11"
[main f86ff69] learn(lpic-106): Install and configure X11
1 byte changed, 3 insertions(+)
See it on your path Already committed . Try the questions again any time, it won't undo anything. To uncommit it and start over: