What file should I modify to execute some instructions when any user logs in through gdm?

I tried /etc/bashrc but that is executed ony when starting bash (and each time an xterm is open). I'd like to execute something only once when the user logs in.

What I want to do is to "reset" some user preferences each time the user logs on (including the window manager), so the script should run before the WM is initialized.

  • 4
    Why do you want to annoy your users like that?
    – Keith
    Aug 12, 2011 at 8:12

3 Answers 3


The solution that seems to work best for me is to edit /etc/gdm/PostLogin/Default. This is executed just after the user logs in with gdm. Just what I wanted.


On Debian and derivatives you can modify /etc/profile, don't think it is universal, though.

  • This is only for shell logins - and the OP pointed he was not interested in such solution. Aug 12, 2011 at 7:48
  • 1
    @rozcietrzewiacz: this also works for GDM logins, because it reads /etc/profile (see /etc/gdm/Xsession). There is not a general rule for all DMs, I think.
    – enzotib
    Aug 12, 2011 at 8:21
  • Hm... Maybe it is, I don't know - but did you check when else it is sourced? One can do some testing of the login setup of course, but then you should describe this approach more. Aug 12, 2011 at 8:47

From the man page:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

When a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists.

When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of /etc/bash.bashrc and ~/.bashrc.

For change the WM of your users: uninstall kdm/gdm/xdm/slim, setup the WM in ~/.xinitrc and run "startx" from your bash config.


You must log in to answer this question.

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