Execute a shell script every time a new user is created

What would be the easiest way to execute a command every time a new user is added?

I checked through /etc/adduser.conf , but there is nothing, it seems like it will do it?

I was thinking of adding it to users .bashrc , so it starts when I log in, but I would prefer it to be configured before they are logged in.

Any help would be appreciated.

+6
source share
3 answers

From man adduser :

  If the file /usr/local/sbin/adduser.local exists, it will be exe‐ cuted after the user account has been set up in order to do any local setup. The arguments passed to adduser.local are: username uid gid home-directory 

It looks like you can add your actions to create a user here.

+10
source

I don’t know the direct path ... But you can check the changes in the /etc/passwd or /home directrory using, for example, inotifywait or using some kind of cron job.

0
source

I did this a few years ago by writing a custom script that I need, and I call adduser inside the script to add the user to the system.

0
source

All Articles