Create a logoff script/task for Linux

In similar vein to my question for Windows and Mac OS X, how would one go about creating a logoff script for Linux?

Any distro is fine, as I'm sure it'd be extendable across others. I'm most familiar with RHEL/CentOS/Fedora and Ubuntu, though.

addition
If this exists for both a graphical login (ie at a lcoal workstation) and for a remote login (such as via ssh), that'd be ideal - but I'd settle for one or the other if both aren't possible.


For remote SSH sessions, it's the job of your shell to handle any on-logout scripting. The Bash shell typically runs ~/.bash_logout.

For X sessions, the login manager controls on-logout scripting. File locations depend on which login manager is in use. The Xserver is not running when the on-logout script is executed, so don't include any programs in the script that try to access the display.

  • For Gnome, use /etc/gdm/PostSession/Default for a system-wide default logout script (runs no matter who's logging out). Unlike Bash's logout script, I don't think there's a user-specific version of a GDM PostSession script.

  • XDM uses a Reset script is installed to /etc/X11/xdm/Xreset.

  • For KDE (using KDM), you want the Reset script. KDE3 uses /etc/kde3/kdm/Xreset. The location may be specified in KDM's configuration file, /etc/kde3/kdm/kdmrc, with the Reset key.

  • WDM apparently uses a pair of Reset scripts: a per-display script at /etc/X11/wdm/Xreset_0 (for display :0), and a global script at /etc/X11/wdm/Xreset. The WDM configuration file is in /etc/X11/wdm/wdm-config.

The file locations in this answer are from Debian packages. Ubuntu packages will generally use the same files, but other distributions may use alternate locations.


If the distro uses PAM to authentificate users, you can install pam_script to provide onsessionopen/onsessionclose funcionality.

I use it in Debian based distros to check files modified by users thru scp only and adjust the files' permissions.

You can download pam_script from freecode.