For remote SSH sessions, it's the job of your shell to handle any on-logout scripting. The Bash shell typically runs
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
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
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
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.