skip to content
 

Using a .xsession file on Ubuntu

Introduction

The default graphical desktop in Maths is XUbuntu. Other options including GNOME and KDE are available by selecting them from the graphical login screen. If you are happy with one of these you do not need to read any further on this page.

If you do not like any of the default options this page will tell you how to customise your session yourself.

A simple .xsession file

You will need to create a file in your home directory called .xsession. This is simply a shell script which starts the programs you want to run when you log in. Here's a commented sample:

#!/bin/bash

# Set background to a nice green colour
# (read /usr/share/X11/rgb.txt for a list of colour names)

xsetroot -solid seagreen

# A clock.  Notice the ampersand (&) which puts it in the
# background so that your script starts the clock and then
# carries on running.

xclock -geom 75x75-59+2 &

# An xload, showing you how busy this computer is

xload -geom 75x75-143+2 &

# An xterm

xterm &

# Finally, we start a window manager.  We want quitting the
# window manager to end the session, so this command does not
# have an ampersand on the end:

fvwm

# And when fvwm quits, we reach the end of this script and the
# session ends.

You will need to make sure that this script is executable with chmod +x .xsession.

Trying it out

At the graphical login screen, enter your username and then choose User Script from the session menu at the bottom of the screen. When you enter your password it should run your .xsession file!

If you mess it up so that when you log in it goes straight back to the login screen, you've probably put an ampersand on all of the commands in your .xsession. The last command in the file, usually your window manager (e.g. fvwm), needs not to have an ampersand after it. You can log in using XUbuntu or one of the other desktops to investigate what went wrong.

If your script results in you having a session you can't use to start windows etc. you can press Ctrl-Alt-Backspace to get back to the graphical login screen. Usually this happens when you forget to put an ampersand after one of the commands you put in your .xsession file.

What happened to .xsession_extra?

.xsession_extra was an old DAMTP configuration file for customising the graphical user interface. It is no longer supported on Ubuntu. Any commands you would once have put in .xsession_extra should now go in .xsession.

I have a .Xsession which used to work but doesn't under Ubuntu

.Xsession with a capital X was an alternative name for .xsession used by a few users in the Atmosphere Ocean Dynamics Group. This file is now ignored by Ubuntu. If you want to use it please rename it to .xsession with a lower-case X.