What is the difference between starting x and starting the display manager?
The graphical user interface on traditional Unix systems, as well as most modern Unix systems other than Mac OS X, is built on the X Window System. One component, the X server, communicates with the hardware (display and input peripherals) and offers basic primitives to display windows and route user input. Other programs, said to be X clients, display windows and listen to user input by communicating with the X server.
In order to talk with the hardware, an X server may require special privileges; for example, on some systems, the X server is setuid root. Recent systems try to avoid having the X server run as root in order to improve security. Depending on the system, running an X server on the system console may be restricted to certain users, or to the user with physical access to the console.
The X server alone does nothing but display a hard-coded background pattern and a mouse cursor. In order to do anything useful, some clients need to be started, typically including a window manager.
The normal way to run a GUI session is to run a session manager program, which takes care of launching all desired clients (window manager, desktop widgets, clipboard manager, restored programs from the user's previous session, etc.). The session manager needs to be started after the X server since it will interact with it. Each desktop environment comes with its own session manager; just about any window manager can also be used as a session manager, and in a pinch a terminal running a shell can be seen as a minimalistic session manager — what matters is that the user has some way to launch the programs they want to run.
There are two traditional ways to launch a GUI session:
- If a user is already logged in, but they don't have a GUI yet, they can run the
xinit
command. This command starts an X server, then starts a session manager, and waits for the session manager to exit; then it kills the X server. This way, the client side of the session and the X server have the same lifetime. Thestartx
program is a small wrapper aroundxinit
. - It's also possible to start a GUI before any user is logged in. In that case, the only client is a display manager, which provides a login prompt. Once a user has logged in, the display manager invokes their session manager. When the session manager exits, the display manager ensures that no more programs are running in that session, and shows a new login prompt.
Another way to see this is that in order to have a graphical login session, there needs to be a graphical interface and the user needs to log in. These two steps can be performed in either order: login then start the GUI (startx
method), or start the GUI then login (display manager method).
Other setups are uncommon but possible. For example, in a kiosk setup, the system startup scripts start an X server and a single full-screen client. In an autologin setup, the display manager runs a session manager for the default user at boot time.
Generally, a unix system requires root to start X (or a display manager, which runs within X).
Without a display manager, if root starts X then the current user of the X session is root.
With a display manager, root starts X and the display manager, but then allows other users to start sessions within that environment. This means that even though it took root to start X, a "normal" user can now take control and run all the processes safely.
Root, however, still "owns" the X session. Unless you have granted a user permission (by adding that user to the appropriate group) to do big important things like Shutdown or Restart, the user is not able to stop X. Only root can do that. That's sometimes important on a multi-user system, where you don't want users to suddenly decide to restart the machine, destroying other sessions in the process.