I'm running a more or less standard installation of Ubuntu Precise 12.04 and I am quite satisfied with doing everydays task with Unity desktop environment.

When it comes to playing, however, I feel much more comfortable with LXDE (background: in it's current state, Unity archieves much lower framerates than e.g. Unity 2D or LXDE - it's a known bug and being worked on).

For that purpose I created a gamer user profile and now I want to restrict it to use LXDE desktop environment only.

To elaborate this further: when asked to login after boot I want only LXDE to appear as an option for the gamer user profile at the login-screen while my standard user profile should still have the option to choose which desktop environment to use.

Thanks in advance for any insight that may be of help!

  • It should keep your last choice as the default for the next time. Is it not doing this? Is there a reason you don't want the other options, if it were defaulting to the correct desktop environment? – reverendj1 Aug 21 '12 at 16:57
  • I noticed this behaviour too after I asked the question. Basically, that's already what I wanted and why I asked. Aside from that, I'm still interested in a solution - I need to learn more about groups & permissions '') I'm very surprised that this seems to be such a huge problem. Is it impossible to accomplish? – FuzzyQ Aug 22 '12 at 6:00

Okay, from my understanding of LightDM (the login manager) it does not seem supported to restrict the desktop environments for a specific user. It is an all or nothing deal. By default, when a user chooses a desktop environment, that will become their default desktop environment. When they log in next time, unless they choose another one, they will be logged in to their default.

You can, however, make it so the user cannot change this. This user will still be able to select a different desktop environment, but if they do, it will not change their default. I believe this is the safest way to do this, if you are not worried that the person will change it. All you have to do is edit their .dmrc file (located in their home directory, i.e. /home/user). This is where their default session is stored. Change the Session variable in that file to whatever you want, i.e. ubuntu is the default Unity DE, ubuntu-2d is Unity 2D, and LXDE is LXDE. To make it so this will not be changed if they log in with another DE, we can simply make it immutable (unchangeable):

sudo chattr +i /home/user/.dmrc

Now no one will be able to change that file (root and other programs included) unless you remove the immutable flag:

sudo chattr -i /home/user/.dmrc

If you absolutely DO NOT want this user to ever log in with another DE, I did figure out a really hacky way (i.e. do this at your own risk) to accomplish this. I was kind of bored and this seemed like a fun thing to try. All of the different DEs that LightDM can see are kept at /usr/share/xsessions as .desktop files. FYI, you can delete any of these you don't want showing up at the login screen (but that will remove it for ALL users). If you open any one of these, they are fairly straightforward. They are basic desktop launcher files, just like all of the shortcuts on your desktop. Each one contains an Exec line, which is what gets executed when you choose your DE at the login screen (i.e. which DE gets launched). We are going to take advantage of this and check which user is logging in. If the user is our restricted user, we will force them to use a certain DE.

First, for each .desktop file in /usr/share/xsessions/ you will need to create a script in /usr/local/bin. For my example, I will be showing how to do this for ubuntu.desktop, which is the Unity DE, and using LXDE as the DE we are forcing our restricted user (restricteduser) to use. Looking at LXDE.desktop, we can see that the Exec command is /usr/bin/startlxde and there is no TryExec command. When you open ubuntu.desktop we see that the Exec command is gnome-session --session=ubuntu and the TryExec command is unity. The TryExec command is just what it sounds like. After running the Exec command, it will try running the TryExec command, but if it fails, it won't crash.

Now, taking those commands we got from the .desktop files we can create our scripts. We will put them in /usr/share/bin. We will need to make two, one for the Exec and one for the TryExec. We'll do something like this:



if [ `/usr/bin/whoami` = "restricteduser" ] ; then
   gnome-session --session=ubuntu



if [ `/usr/bin/whoami` != "restricteduser" ] ; then

We are just testing whether the person logging in is our restricted user, and firing up the appropriate DE. Now, we need to make sure they are executable:

sudo chmod +x /usr/local/bin/ubuntude.sh
sudo chmod +x /usr/local/bin/ubuntudetry.sh

We now need to change our ubuntu.desktop so that it will call our scripts, instead of the actual DEs. Comment out the Exec and TryExec lines in the file, and replace them with this:


Just repeat the process for any other DEs you may have. If there is no TryExec for a DE, then there is no need to create a detry.sh script for it either, as LXDE does not use a TryExec. Obviously this is a bit hacky, and you should make sure that you back up any files before editing them, but it will work if you absolutely need to make sure that a user is logging in to the correct DE.

  • 1
    First of all: thanks for your elaborate answer! This is quite a cunning approach. But if I get that last part right, it will force the restricted user to log in to lxde no matter which option he chose in lightdm. But it will still show all the other options listed in /usr/share/xsessions/, am I getting this right? In this case, I'd rather go with option 1. It's a shame there is no user specific option to set up desktop environment sessions. Removing unwanted xsessions from a user folder would be both handy and simple. – FuzzyQ Aug 22 '12 at 16:30
  • 1
    You're welcome. I kind of took it as a challenge, and I've been meaning to dig in to LightDM more. Right, the user will still see all of the other options, it just doesn't matter, as they will be forced to use LXDE. Like I said, the .dmrc file is there to keep user-specific defaults, but yeah, there is not a built-in way to force a user to use only certain DEs, or restrict which ones they can see/use. It's everyone or no one, without the hack I presented. – reverendj1 Aug 22 '12 at 16:36

on Debian Squeeze and Wheezy you can also add an .xsessionrc with a single line


(where XXX ist your forced session-script see Exec-Line above) in the user homedirectory to force a certain session type regardless of what the user has chosen.

Should also work on Ubuntu.

(Take a look into /etc/X11/Xsession.d/40x11-common_xsessionrc and 50x11-common_determine-startup to see, why this works)


The answer from reverendj1 was not working for me. Reason could be that the value you specify in Exec= is not executed directly, but passed to the /etc/X11/Xsession as an argument. (source: https://askubuntu.com/a/857420/873016)

Another solution to the problem:
1. Backup all /usr/share/xsessions/.desktop files
2. Delete all /usr/share/xsessions/
.desktop files
3. Create only /usr/share/xsessions/default.desktop with

[Desktop Entry]
Comment=This session is the default session. It will look up the user specific desktop session in ~/.xsession.

"default" is a key word for Xsession and will look up the specific session in the user's directory.
4. Now create a /home/{username}/.xsession file for every username. For a "kiosk-like" app, this should look like this :


cd /home/{yourUsername}/ && ./startApplication.py

If e.g. another user should be allowed to start a full blown desktop manager, it could look like this:


exec icewm-session
  1. Make sure the ~/.xsession file is executable
sudo chmod +x ~/.xsession

Tested on ubuntu 16.04 with lightdm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.