bsmoo
bsmoo

Reputation: 1059

Execute shell script everytime a new user is created

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

I checked through /etc/adduser.conf but nothing is in there which looks like it will do this?

I thought about added it to the users .bashrc so it jsut executes when they login, but I would rather have it setup before they have logged in.

Any Help would be appreciated.

Upvotes: 14

Views: 7813

Answers (3)

Oleg S Kleshchook
Oleg S Kleshchook

Reputation: 464

I do not know direct way... But, you can check for changes in /etc/passwd file or /home directrory, using, for example inotifywait or using some cron job.

Upvotes: 1

diwhyyyyy
diwhyyyyy

Reputation: 6372

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

Looks like you can add your user-creation actions here.

Upvotes: 24

Alepac
Alepac

Reputation: 1831

I did this some years ago writing a custom script that does everithing I need and calling adduser inside the script to add the user to the system.

Upvotes: 1

Related Questions