This forum has been archived. All content is frozen. Please use KDE Discuss instead.

KDM: prevent a user from having multiple graphical sessions

Tags: None
(comma "," separated)
samuelm1
Registered Member
Posts
4
Karma
0
OS
Ever since I began using KDE, I found it slightly annoying that KDM would allow any user to have more than one graphical session running at the same time. On Windows, Mac, and other DEs on Linux, if a user tries logging in again and creating another session, he/she is usually redirected to his/her currently running session, and his/her account is unlocked. I wanted KDM to have the same behavior, but as far as I could find, there were no configuration directives for that. So I did some searching, and found that KDM executes a shell script called "Xstartup" (in my case, the script was located in /etc/kde4/kdm) before starting a graphical session. I finally got KDM working the way I wanted it to by editing this script. If anyone else would like to configure their installation of KDM this way, here's what to do:

Open up the file /etc/kde4/kdm/Xstartup (it might be located somewhere else on your system, depending on your distro) and do the following changes:

Replace the statement in the first line of the file with this statement:

Code: Select all
#!/bin/bash


Then, remove the following line from the end of the file:

Code: Select all
/sbin/initctl -q emit desktop-session-start DISPLAY_MANAGER=kdm USER=$USER


After that, add the following lines to the end of the file:

Code: Select all
SESSIONS=$(/usr/bin/kdmctl list | grep $USER)
if [ "${SESSIONS:0:2}" == "ok" ]; then
            SESSIONS=(${SESSIONS//\\t/ })
            for i in ${SESSIONS[@]}
            do
                    find_user=$(echo $i | grep $USER)
                    if [[ "$find_user" != "" && "${i:0:1}" == ":" ]]; then
                            X_DISPLAY=${i:0:2}
                            break
                    fi
            done
            if ["$X_DISPLAY" == ""]
            then
                    /sbin/initctl -q emit desktop-session-start DISPLAY_MANAGER=kdm USER=$USER
            else
                    kdmctl activate $X_DISPLAY
                    DISPLAY="$X_DISPLAY"
                    su --preserve-environment -c "/usr/bin/qdbus org.kde.screenlocker /MainApplication quit" $USER
                    exit 1
            fi
else
            /sbin/initctl -q emit desktop-session-start DISPLAY_MANAGER=kdm USER=$USER
fi


Then, save the file.

These changes to the script make KDM behave in the following way:

As normal, if you enter an incorrect password, it won't let you login.

If you do enter a correct username/password combination and do not have an already-running graphical session under your username, KDM will login you in as normal.

If you do enter a correct username/password combination and have an already-running graphical session under your username, KDM will terminate the currently running new session that you started, transfer you back to your already running session, and unlock your screen.

Enjoy!

samuelm1

P.S. You need the qdbus executable in order for screen unlocking to work. Also, screen unlocking will not work for non-KDE graphical sessions running under KDM.

P.P.S. This script does not limit the number of simultaneous TTY sessions that a user can have; it only limits the user's graphical sessions (to one).

Edit: I found out that the above code actually prevents the user from locking his screen again until he/she logs out and back in again. Sorry about that. I fixed that problem in the code above.
ChrisFor
Registered Member
Posts
1
Karma
0
How can that be done in Plasma 5? To have a unique graphical user session is default for all other OSes. It should be the same for KDE, cause its user intuitive, esp. for those who are not experts (like other family members)
Thanks for help in advance!
airdrik
Registered Member
Posts
1854
Karma
5
OS
In (recent versions of) Plasma 5, the lockscreen provides the ability to switch to other open sessions in addition to starting new sessions.

A couple of other notes: In Plasma 5, KDM was abandoned and replaced by SDDM (which is a 3rd party project). You might check SDDM's wiki to see if they have this feature and how to enable it or ensure the ticket is raised on their issue tracker.

You can also use other Display Managers such as LightDM or GDM if any of them provide this feature.


airdrik, proud to be a member of KDE forums since 2008-Dec.


Bookmarks



Who is online

Registered users: Bing [Bot], gfielding, Google [Bot], Sogou [Bot]