Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute shell script everytime a new user is created

Tags:

bash

shell

ubuntu

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.

like image 865
bsmoo Avatar asked Mar 22 '13 10:03

bsmoo


People also ask

How do I run a shell script from a different user?

Running Script as Another User. By default, the su command takes an input a target username to switch into. However, we can specify a script to be run with the flag -c. When specified, su command will just execute the script without dropping into a new shell as the target user.


2 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

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

like image 100
Inductiveload Avatar answered Oct 14 '22 14:10

Inductiveload


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.

like image 34
Alepac Avatar answered Oct 14 '22 14:10

Alepac