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:

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

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,

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

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

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.

Win the battle. Social Warfare Dynamik Website Builder Author Pro

Leave a Reply

Be the First to Comment!

Notify of
wpDiscuz

Free to your inbox

Join our mailing list to receive the latest news and updates from JournalXtra.

You have Successfully Subscribed!