How to Make a Basic Custom Xsession Script

If you cannot startx or xorg or init or any other desktop session start up script without being a super user i.e you have to type sudo startx to begin a new Linux session then you will need to create an xsession script or an xinitrc script or an xserverrc script.

Word to the Wise: It is a bad idea to start a desktop session as root.

Xsession is a file. It is a dot file. A dot file is one that has a period symbol before it. The period sign before the file name tells us that .xsession is a hidden file that non admin users do not normally see, know about or edit.

The xsession program is a session manager.  It is normally executed by your ~/.xinitrc (or ~/.xsession) script and controls your X Window session. As soon as it is started, xsession launches a window manager and some applications of your choice. At anytime during your session, you may switch to another window manager or execute some other applications from the xsession menus ~ source.

How to make an xsession script

Confirm that an xsession script does not already live in the home directory of the logged in user account before you create a custom xsession script. If one already exists, rename it then try to start the desktop session again.

Create a file called .xsession in the home folder of the user who wants to run a custom desktop session then place the following text into it:

#!/bin/sh
# Each line here tells Xorg to load a specific desktop environment when a desktop session is created.
# Remove the hash sign (#) to uncomment the instruction you want Xorg to execute.
# Prepend a hash sign to any line to comment it out.
# Only one line should be uncommented.
# Only uncomment an instruction if you have the required environment installed
# KDE is uncommented by default

# exec afterstep # AfterStep
# exec blackbox # Blackbox
# exec enlightenment # Enlightenment
# exec fluxbox # Fluxbox
# exec startfluxbox # Fluxbox
# exec fvwm # FVWM
# exec fvwm2 # FVWM2
# exec gnome-session # GNOME
# exec icewm # IceWM
# exec ion #
# exec mwm # Motif
# exec openbox # Openbox
# exec openbox-session # Openbox
# exec pekwm
# exec qvwm # qvwm
# exec /usr/bin/ratpoison
exec startkde # KDE
# exec startlightdm # LightDM
# exec startlxde
# exec startxfce4 # XFce 4
# exec wmaker # WindowMaker
# exec xfce # XFce 3
# exec xterm
# ...or another installed Display Manager

This can be done using the command line

You can create the xsession file in the home directory of the user logged into the terminal from the command-line by executing the command

sudo touch ~/.xsession

The important part of the file is the exec command so you only need to add the relevant exec line into the file. This can be done from the command line with, for example,

sudo sh -c "echo -e '#!/bin/sh\nexec startkde\n' >> ~/.xsession"

Replace “startkde” with whatever session type you want to start.

The .xsession script needs to be made executable for it to work. Make it so with

chmod +x ~/.xsession

You can edit the .xsession script from the command-line with Nano:

sudo nano ~/.xsession

The above instructions can be used to create and edit the files .xinitrc and .xserverrc, when needed.

To copy the custom .xsession file to .xinitrc, use

cp ~/.xsession ~/.xinitrc

You will need to start (or restart) the display manager to run the custom xsession script.

What’s the difference between xsession and xinitrc?

Xsession is used by graphical login managers like kdm and gdm. Xinitrc is used by startx, xorg and init.

Sharing is caring!

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x