Wednesday, August 26, 2009

Auto Login + Lock Screen in Ubuntu

First create (as root) the script /usr/bin/gnome-locked-session with the following content:
#!/bin/bash
beryl-manager
gnome-screensaver
gnome-screensaver-command --lock
exec gnome-session

(beryl-manager seems to have to be started before gnome-screensaver as if I start it normally it makes things buggy, like masking the screensaver or so)

Then give it execution rights: sudo chmod +x /usr/bin/gnome-locked-session

now create (still as root) the file /usr/share/xsessions/gnome-locked.desktop with the following content:
[Desktop Entry]
Encoding=UTF-8
Name=GNOME (locked)
Name[fr]=GNOME (verrouillé)
Comment=This session logs you into GNOME and locks the screen immediately
Comment[fr]=Cette session vous connectera dans GNOME et verrouillera l'écran immédiatement
Exec=/usr/bin/gnome-locked-session
# no icon yet, only the top three are currently used
Icon=
Type=Application

Then if it is not already done, configure the auto-login.

Logoff (well... read the rest before ;-)). At the logon, click "Session" or so (maybe in an "Options" menu) and choose "GNOME (locked)". Login and select "Define as the default session". That's it ! Your session should now start locked, as every time you'll restart your computer :-)

Further if you want to login without locking the screen (for example if you logged off to allow another user to login, then want to login again), you may choose the session "GNOME" at the login screen, then login. Just don't define it as the default session as it would break the auto-login-then-lock configuration...

The gnome-locked-session script might perhaps be tweaked to detect if the session was started automatically but I don't know how... (well, It could simply check the uptime but it won't be very reliable...) Perhaps GDM defines some environment variable that could be used to detect if the session was started automatically ?

1 comment:

  1. Using an auto log in lock in your gadget could really help a lot. It is especially fi you are protection important files.

    ReplyDelete