Setting up a Graphical Login


Setting up a Graphical Login

Setting up your Linux workstation to display a graphical login screen is easy—all you have to do is make the appropriate selection during the installation. Even if you have not initially elected to have a graphical login screen, you can easily set it up once you know the details. The following sections explain how your Red Hat Linux system displays the graphical login screen.

Understanding How init Starts the Display Manager

A process named init starts the initial set of processes on your Red Hat Linux system. What init starts depends on the current run level, the contents of the /etc/inittab file, and the shell scripts located in the /etc/rc.d directory and its subdirectories. For now, you don’t need to understand the details; you must know, however, that the graphical login screen starts at run level 5.

Cross Ref 

Chapter 20 describes in detail the init process, the /etc/inittab file, and the Red Hat Linux boot process.

The last line of the /etc/inittab file is responsible for starting the graphical login process with the following entry (the number 5 denotes run level 5):

x:5:respawn:/etc/X11/prefdm -nodaemon

This command runs /etc/X11/prefdm, a shell script that contains the following lines:

#!/bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin

# Shut down any graphical boot that might exist.
if [ -x /usr/bin/rhgb-client ]; then
    /usr/bin/rhgb-client -quit
fi

# We need to source this so that the login screens are translated.
[ -f /etc/profile.d/lang.sh ] && . /etc/profile.d/lang.sh

# Run preferred X display manager
# Try autologin first, if wanted...
if [ -f /etc/sysconfig/autologin -a -x /usr/sbin/autologin ]; then
     if /usr/sbin/autologin; then
            exit 0
     fi
     # If autologin fails (bad permissions, etc.), we get here -
     # time to start a real display manager.
fi

preferred=
if [ -f /etc/sysconfig/desktop ]; then
     . /etc/sysconfig/desktop
     if [ "$DISPLAYMANAGER" = GNOME ]; then
            preferred=gdm
     elif [ "$DISPLAYMANAGER" = KDE ]; then
            preferred=kdm
     elif [ "$DISPLAYMANAGER" = XDM ]; then
            preferred=xdm
     fi
fi

if [ -z "$preferred" ]; then
     if which gdm >/dev/null 2>&1; then
            preferred=gdm
     elif which kdm >/dev/null 2>&1; then
            preferred=kdm
     elif which xdm >/dev/null 2>&1; then
            preferred=xdm
     fi
fi

if [ -n "$preferred" ] && which $preferred >/dev/null 2>&1; then 
     exec `which $preferred` $* >/dev/null 2>&1
fi

if which gdm >/dev/null 2>&1; then
     exec `which gdm` $* >/dev/null 2>&1
elif which kdm >/dev/null 2>&1; then
     exec `which kdm` $* >/dev/null 2>&1
elif which xdm >/dev/null 2>&1; then
     exec `which xdm` $* >/dev/null 2>&1
fi

# Catch all exit error
exit 1

This script starts a specific display manager—gdm, kdm, or xdm—depending on the setting of the DISPLAYMANAGER variable in the /etc/sysconfig/desktop file. The display manager is a program responsible for displaying the graphical login window, authenticating users who log in, running initialization scripts at the start of a session, and cleaning up after the session. The display manager process manages the display, making it available to the users and cleaning up after the user finishes a session. Note that of the three display managers—gdm, kdm, or xdm—xdm is the most generic.

If you have not enabled the graphical login screen during Red Hat installation, you can do so by editing the /etc/inittab file. Locate the line containing initdefault, and make sure that it reads as follows:

id:5:initdefault:
Caution 

Before you edit the /etc/inittab file, you should know that any errors in this file may prevent Linux from starting up to a point at which you can log in. If you cannot log in, you cannot use your system.

After editing the default run level in /etc/inittab, you can either reboot the system or type the following command to switch to run level 5:

telinit 5

Learning the GNOME Display Manager (gdm)

The gdm program is a display manager similar to xdm, the X display manager. Like xdm, gdm starts an X server for each local display, displays a login dialog box, and enables the user to log in to the system. Figure 9-1 shows a typical graphical login screen displayed by gdm.

Click To expand
Figure 9-1: Graphical Login Screen Managed by gdm.

When gdm runs, it reads various configuration parameters from the configuration file /etc/X11/gdm/gdm.conf, which has a structure similar to a Windows INI file. For example, here is a typical gdm.conf file:

[daemon]
AlwaysRestartServer=false
AutomaticLogin=
AutomaticLoginEnable=false
Chooser=/usr/bin/gdmchooser
Configurator=/usr/sbin/gdmsetup --disable-sound --disable-crash-dialog
DefaultPath=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin
DisplayInitDir=/etc/X11/gdm/Init
FailsafeXServer=
FirstVT=7
FlexibleXServers=5
GnomeDefaultSession=/usr/share/gnome/default.session
Greeter=/usr/bin/gdmgreeter
Group=gdm
HaltCommand=/usr/bin/poweroff;/sbin/poweroff;/sbin/shutdown -h now;/usr/sbin/shutdown -h now
KillInitClients=true
LocalNoPasswordUsers=
LogDir=/var/log/gdm
PidFile=/var/run/gdm.pid
PostSessionScriptDir=/etc/X11/gdm/PostSession/
PreSessionScriptDir=/etc/X11/gdm/PreSession/
RebootCommand=/sbin/shutdown -r now;/usr/sbin/shutdown -r now
RemoteGreeter=/usr/bin/gdmlogin
RootPath=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin
ServAuthDir=/var/gdm
SessionDir=/etc/X11/gdm/Sessions/
StandardXServer=/usr/X11R6/bin/X
SuspendCommand=
TimedLogin=
TimedLoginDelay=30
TimedLoginEnable=false
User=gdm
UserAuthDir=
UserAuthFBDir=/tmp
UserAuthFile=.Xauthority
VTAllocation=true
XKeepsCrashing=/etc/X11/gdm/XKeepsCrashing
Xnest=/usr/X11R6/bin/Xnest -name Xnest

[security]
AllowRemoteAutoLogin=false
AllowRemoteRoot=true
AllowRoot=true
RelaxPermissions=0
RetryDelay=1
SessionMaxFile=524388
UserMaxFile=65536

[xdmcp]
DisplaysPerHost=1
Enable=false
HonorIndirect=true
MaxPending=4
MaxPendingIndirect=4
MaxSessions=16
MaxWait=15
MaxWaitIndirect=15
Port=177
Willing=/etc/X11/gdm/Xwilling

[gui]
GtkRC=/usr/share/themes/Bluecurve/gtk-2.0/gtkrc
MaxIconHeight=128
MaxIconWidth=128

[greeter]
BackgroundColor=#27408b
BackgroundImage=
BackgroundProgram=
BackgroundRemoteOnlyColor=true
BackgroundScaleToFit=true
BackgroundType=0
Browser=false
ConfigAvailable=false
DefaultFace=/usr/share/pixmaps/nobody.png
Exclude= bin,daemon,adm,lp,sync,shutdown,halt,mail,news,uucp,operator,nobody,gdm,postgres,pvm,rpm
GlobalFaceDir=/usr/share/faces/
GraphicalTheme=Bluecurve
GraphicalThemeDir=/usr/share/gdm/themes/
Icon=/usr/share/pixmaps/gdm.png
LocaleFile=/etc/X11/gdm/locale.alias
LockPosition=true
Logo=
MinimalUID=500
PositionX=0
PositionY=0
Quiver=true
RunBackgroundProgramAlways=false
SetPosition=false
ShowGnomeChooserSession=false
ShowGnomeFailsafeSession=false
ShowXtermFailsafeSession=false
SystemMenu=true
TitleBar=false
Use24Clock=false
UseCirclesInEntry=false
Welcome=Welcome to %n
XineramaScreen=0

[chooser]
Broadcast=true
DefaultHostImg=/usr/share/pixmaps/nohost.png
HostImageDir=/usr/share/hosts/
Hosts=
ScanTime=3

[debug]
Enable=false

[servers]
0=Standard

[server-Standard]
command=/usr/X11R6/bin/X
flexible=true
name=Standard server

The [servers] section of the file specifies the displays on which gdm displays the login dialog box. Each line of this section starts with a display number and shows the command needed to start the X server.

You see the term greeter used often in the display manager configuration file. Greeter refers to the login screen—the user interface through which the display manager prompts the user to log in to the system.

The different sections in the configuration file control different aspects of the graphical login screen as well as the tasks the user can perform from that screen. Table 9-1 describes the gdm configuration options, organized by sections.

Insider Insight 

Edit the Welcome= line to change the welcome message on the graphical login screen. The default message says welcome to the hostname, which can be somewhat cryptic. You can edit that line and change the message to something more meaningful with the syntax Welcome=Welcome to XYZ Corp.

Table 9-1: The gdm Configuration Options

Configuration Option

Description

[daemon] section

 

AlwaysRestartServer=true or false

If set to true, gdm always kills the existing X server and starts a new one.

AutomaticLoginEnable=true or false

If set to true, automatically log in the user specified in the AutomaticLogin option without asking for any password.

AutomaticLogin=username

If a user name is specified and AutomaticLogin Enable is true, that user is logged without asking for a password.

Chooser=chooserprogram

Full path and name of the gdmchooser executable file (typically, this should be /usr/bin/gdmchooser)

Configurator=chooserprogram

Full path and name of the gdmconfig executable file (typically, this should be /usr/bin/gdmconfig)

DefaultPath=pathname

Path (names of directories separated by colons) to be used for the user’s session

DisplayInitDir=pathname

Directory containing the initialization scripts (the default is /etc/X11/gdm/Init)

FailsafeXServer = safex-script

Full path name of script that gdm should run to provide a failsafe GUI login screen

FirstVT =number

The virtual terminal (VT) number where X should be run (default is 7)

FlexibleXServers =count

Maximum number of X servers to run

GnomeDefaultSession= sessionfile

Full path name of file that gdm should read if there are no user GNOME session files (the default is /usr/share/gnome/default.session)

Greeter=greeterprogram

Full path and name of the greeter executable file, followed by arguments (typically, this should be /usr/ bin/gdmlogin)

Group=groupname

Group name under which gdmlogin and gdmchooser are run (the default is gdm)

HaltCommand=haltprogram

Full path and arguments to the commands to be executed when the user selects Halt from the System menu (typically, this should be /sbin/shutdown -h now)

KillInitClients=true or false

When set to true, gdm kills the X clients started by the Init scripts after the user logs in (the default is true).

LocalNoPasswordUsers = userlist

Comma-separated list of users that are allowed to log in without password

LogDir=pathname

Directory containing the log files for the displays (the default is /var/log/gdm)

PidFile=pidfile

Name of the file where the process ID (pid) of the gdm process is stored (the default is /var/run/gdm.pid)

PostSessionScriptDir=pathname

Directory that contains the PostSession scripts—scripts run after the user logs out (the default is /etc/X11/gdm/ PostSession/)

PreSessionScriptDir=pathname

Directory that contains the PreSession scripts—scripts run right after the user logs in (the default is /etc/X11/ gdm/PreSession/)

RebootCommand=rebootprogram

Full path and arguments to the command to be executed when the user selects Reboot from the System menu (typically, this should be /sbin/shutdown -r now)

RemoteGreeter =pathname

Full path name of the greeter executable file for remote displays

RootPath=pathname

Path (names of directories separated by colons) to be used for the root user’s session

ServAuthDir=pathname

Directory (the default is /var/gdm) containing the X authentication files for the displays (this directory should be owned by user gdm, group gdm, with permission 750)

SessionDir=pathname

Directory containing scripts for all session types available on the system (the default is /etc/X11/gdm/Sessions)

StandardXServer =pathname

Path name of standard X server (the default is /usr/X11R6/bin/X)

TimedLogin=username

If a user name is specified and TimedLoginEnable is true, then that user is logged without asking for any password after the login screen is inactive for the number of seconds specified in the TimedLoginDelay option

TimedLoginDelay=N

The number of seconds delay before the user specified in TimedLogin is automatically logged in

TimedLoginEnable=true or false

If set to true, automatically logs in the user specified in the TimedLogin option without asking for any password

User=username

User name under which gdmchooser and gdmlogin are run (the default is gdm)

UserAuthDir=pathname

Directory where the user’s .Xauthority file should be saved (if this field is empty, the user’s home directory is used, which is the default)

UserAuthFBDir=pathname

Directory where a fallback cookie (which simply refers to the small amount of authentication information) is created if gdm fails to update the user’s .Xauthority file (the default is /tmp)

UserAuthFile=filename

Name of the file for storing the user’s authentication cookies (the default is .Xauthority)

VTAllocation =true or false

If true, automatically allocate virtual terminal (VT) for use by X server (default is true)

XKeepsCrashing=sessionfile

Full path name of a script that gdm should run if X keeps crashing (the default script is /etc/X11/gdm/ XKeepsCrashing)

Xnest = pathname

Full path name of the nested X server (Xnest) that runs as an X client, but also manages graphics on behalf of the X server (default is /usr/X11R6/bin/Xnest -name Xnest)

[security] section

 

AllowRemoteAutoLogin =true or false

When set to true, allows remote timed login (the default is false)

AllowRemoteRoot=true or false

When set to true, the root user can log in remotely (the default is true)

AllowRoot=true or false

When set to true, the root user can log in at the console (the default is true)

RelaxPermissions=0, 1, or 2

0 = gdm only accepts files and directories owned by the user; 1 = gdm allows group writeable files and directories; 2 = gdm allows world writeable files and directories (the default is 1)

RetryDelay=N

Number of seconds to wait before gdm displays the login window again after a failed login (the default is 3 seconds)

UserMaxFile=N

Maximum size (in bytes) of files that gdm will read or write (the default is 64KB, or 65,536 bytes)

[xdmcp] section

 

DisplaysPerHost =number

Number of displays per host (the default is 1)

Enable=true or false

When set to true, gdm listens on port 177 and supports the X Display Manager Control Protocol (XDMCP) that enables users to log in to other hosts on the network (the default is false)

HonorIndirect=true or false

When set to true, gdm allows remote execution of the gdmchooser client on X terminals (the default is true)

MaxPending=N

Maximum number of pending connections (the default is 4) that gdm should allow (this helps avoid any denial of service attacks)

MaxPendingIndirect=N

Maximum number of gdmchooser clients that gdm will run simultaneously on remote displays (the default is 4)

MaxSessions=N

Maximum number of remote display connections that gdm will accept (the default is 16)

MaxWait=N

Maximum number of seconds that gdm waits for a response from a display before assuming that the display is not active anymore (the default is 15 seconds)

MaxWaitIndirect=N

Maximum number of seconds that gdm waits for a remote display to complete protocol negotiations after the display requests a chooser (the default is 15 seconds)

Port=177

The UDP port number where gdm listens for XDMCP requests (the default is 177)

Willing =pathname

Full path name of script to run to generate replies to XDMCP BroadcastQuery requests (the default is /etc/X11/gdm/Xwilling)

[gui] section

 

GtkRC=pathname

Path name of file that contains the theme to be used by the gdmlogin and gdmchooser programs (the default is the BlueCurve theme, defined in the file /usr/ share/themes/Bluecurve/gtk-2.0/gtkrc)

MaxIconWidth=N

Maximum width (the default is 128 pixels) of icons that the face browser will display (gdmlogin can display a face browser containing icons for all the users on a system; these icons can be installed globally by the system administrator or in the users’ home directories)

MaxIconHeight=N

Maximum height (the default is 128 pixels) of icons that the face browser will display

[greeter] section

 

BackgroundColor =#colornum

Background color

BackgroundImage =pathname

Pathname of image to use as background (when BackgroundType=1)

BackgroundProgram =pathname

Pathname of program to run to draw the background

BackgroundRemoteOnlyColor = true or false

When set to true, displays a solid color background for remote displays (the default is true)

BackgroundScaleToFit = true or false

When set to true, scales image to fit screen (the default is true)

BackgroundType =0, 1, or 2

Type of background for the greeter, 0 = None, 1 = Image, 2 = Color (the default is 0)

Browser=true or false

When set to true, displays a browser, called the face browser, where the faces of all system users are displayed (the default is false)

ConfigAvailable =true or false

When set to true, configuration option is available from the System menu (default is false)

DefaultFace=imagefile

A file, readable by the gdm user, containing an image that is to be displayed if a user does not have a personal picture in the ~/gnome/photo directory (which refers to the gnome/photo subdirectory of the user’s home directory). The default is the /usr/share/pixmaps/ nobody.png file.

Exclude=usernames

Comma-separated list of user names to be excluded from the face browser; the excluded users will still be able to log in

GlobalFaceDir=pathname

Directory where face files (each containing an icon showing a user’s face) are located (the default is /usr/share/faces/)

GraphicalTheme =themename

Name of graphical theme to use (default is BlueCurve)

GraphicalThemeDir =pathname

Directory where graphical theme files are located (the default is /usr/share/gdm/themes/)

Icon=imagefile

A file, readable by the gdm user, containing the image to be displayed when the login window is in iconified state (the default is /usr/share/pixmaps/gdm.xpm)

LocaleFile=localefile

Full pathname for the file in GNU locale format, with entries for all languages supported on the system (the default is /etc/X11/gdm/locale.alias)

LockPosition =true or false

When set to true, the user cannot move the greeter window (the default is true)

Logo=imagefile

A file, readable by the gdm user, with the image to be displayed in the logo area (the default is /usr/share/ pixmaps/gnome-logo-large.png).

MinimalUID =number

Users with this user ID or higher can log in (the default is 500)

PositionX =xpos

Horizontal and vertical position of greeter window PositionY=ypos

Quiver=true or false

When set to true, the gdmlogin program shakes the display (not physically, but by moving the graphics output) when a user enters an incorrect password (the default is false)

RunBackgroundProgramAlways = true or false

When set to true, runs the background program specified by BackgroundProgram (the default is false)

SetPosition =true or false

When set to true, the gdmlogin program shakes the display (not physically, but by moving the graphics output) when a user enters an incorrect password (the default is false)

ShowGnomeChooserSession = true or false

When set to true, shows previous GNOME sessions in the chooser (the default is false)

ShowGnomeFailsafeSession = true or false

When set to true, shows the GNOME failsafe session in the chooser (the default is false)

ShowXtermFailsafeSession = true or false

When set to true, show the failsafe session that runs an xterm window (the default is false)

SystemMenu =true or false

When set to true, show the System menu on the greeter (the default is true)

TitleBar =true or false

When set to true, show a title bar on the greeter window (the default is false)

Use24Clock =true or false

When set to true, use a 24-hour clock no matter what the locale (the default is false)

UseCirclesInEntry =true or false

When set to true, echo the typed password as circles (the default is false)

Welcome=message

The English welcome message that the gdmlogin program displays next to the logo on the login screen (the default message is Welcome to %n, where %n means the node name—the hostname without the domain)

XineramaScreen =number

The Xinerama screen where greeter is displayed (default is 0)

[chooser] section

 

Broadcast =true or false

When set to true, an XDMCP query is broadcast to get the names of all the hosts that accept login (the default is true)

DefaultHostImg=filename

File containing an image to be displayed for those hosts that do not have a unique icon file (the default is /usr/ share/pixmaps/nohost.png)

HostImageDir=pathname

Directory (the default is /usr/share/hosts/) that contains host icon files; each filename matches the host system’s fully qualified domain name (such as yourhost.yourdomain.com).

Hosts=hostnames

Comma-separated names of hosts to list

ScanTime=N

Number of seconds the chooser should wait for replies to its XDMCP broadcast query (the default is 3 seconds)

[debug] section

 

Enable=true or false

When set to true, gdm saves information that can help isolate any bugs in gdm (the default is false)

[servers] section

 

N=ServerName

Name of the X server to start on local display number N (if your system has a single monitor, N is 0). Default is Standard

[server-Standard] section

 

command=ServerPathName

Full pathname of the Standard X server (the default is /usr/X11R6/bin/X)

flexible=true or false

When set to true, the Standard server is considered a flexible server (the default is true)

name=servername

A descriptive name of the Standard server (default is Standard server)

Switching from GNOME to KDE

GNOME and KDE are both capable GUI environments. Red Hat Linux comes with both of these GUIs, but you get GNOME as the default GUI. However, Red Hat also includes the utility script /usr/bin/switchdesk, which enables you easily to switch from one GUI to another, and vice versa. To switch from GNOME to KDE, follow these steps:

  1. From your GNOME desktop, select Main Menu>System Settings>More System Settings>Desktop Switching Tool, or type switchdesk in a terminal window. The Desktop Switcher dialog box appears.

  2. In the Desktop Switcher dialog box, click the KDE radio button to select it (see Figure 9-2), then click the OK button.


    Figure 9-2: Switching to KDE by Using the Desktop Switching Tool.

  3. A message informs you that the desktop configuration has been changed, but you must restart X for the change to take effect. Click the OK button to dismiss the dialog box.

Although the message in Step 3 states that you must restart X, all you need to do is log out of the session and log back in. To log out, select Main Menu>Log Out. When you log in again, you should get the KDE GUI.

The switchdesk utility changes the GUI by creating the appropriate scripts in your home directory. It leaves the display manager unchanged. This means that you use the GNOME display manager, gdm, for login, even when you switch to the KDE GUI. After you log in, gdm executes a session script that eventually executes the .Xclients script in your home directory, if that script exists.

When you run the switchdesk utility, you execute a shell script in the /usr/bin/ switchdesk file that contains the following lines:

#!/bin/sh
echo "Red Hat Linux `basename $0` 3.9"
echo "Copyright (C) 1999-2001 Red Hat, Inc"
echo "Redistributable under the terms of the GNU General Public License"

kicker=`/sbin/pidof "kdeinit: kicker"`
[ -z "$kicker" ] && kicker=`/sbin/pidof kicker`
[ -z "$kicker" ] && kicker=`/sbin/pidof kpanel`
[ -z "$kicker" ] && kicker=`/sbin/pidof kpanel1`
good=1

if [ "$DISPLAY" != "" -a "$1" = "" ]; then
    if [ -n "$kicker" -a -x /usr/bin/switchdesk-kde ]; then
        exec switchdesk-kde
    elif [ -x /usr/bin/switchdesk-gnome ]; then
        exec switchdesk-gnome
    elif [ -x /usr/bin/switchdesk-kde ]; then
        exec switchdesk-kde
    else
        echo "Desktop Switcher GUI unavailable."
        echo "Please install the switchdesk-kde or switchdesk-gnome packages or use"
        echo "switchdesk desktopname."
        good=0;
    fi
else
    good=0;
fi

if [ "$good" = "0" ]; then
    exec switchdesk-helper $1
fi

To switch from KDE to GNOME, log in as root, open a terminal window, and type switchdesk at the shell prompt, then select GNOME as the desktop. After you log out of KDE and log back in, you should get GNOME as your desktop.

Note that if you want to use GNOME for one session only (as opposed to making it your default GUI), simply click Session at the bottom of the login screen, and then select Gnome from the login window menu in the initial login screen, as shown in Figure 9-3.


Figure 9-3: Switching to GNOME for the Current Session Only.

You should get the GNOME desktop for this session. The next time you log in, the system reverts to KDE.

Learning the KDE Display Manager (kdm)

If you install only the KDE desktop or set the DISPLAYMANAGER variable in the /etc/ sysconfig/desktop file to KDE, the kdm program starts the X server for the local display and displays the graphical login window through which you log in to the system. Figure 9-4 shows the graphical login screen that you see when you run the kdm display manager.

When k