9

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!

2
  • 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, 2012 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, 2012 at 6:00

3 Answers 3

5

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:

ubuntude.sh

#!/bin/bash

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

ubuntudetry.sh

#!/bin/bash

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

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:

Exec=/usr/local/bin/ubuntude.sh
TryExec=/usr/local/bin/ubuntudetry.sh

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.

3
  • 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, 2012 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, 2012 at 16:36
  • hahaah This is the way... :) Yes, there isn't a native solution. Dec 14, 2021 at 10:08
1

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

export STARTUP=XXX

(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)

0

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]
Name=Default
Comment=This session is the default session. It will look up the user specific desktop session in ~/.xsession.
Exec=default

"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 :

#!/bin/bash

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

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

#!/bin/bash

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

Tested on ubuntu 16.04 with lightdm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .