Execute shell script everytime a new user is created

删除回忆录丶 提交于 2021-01-21 04:22:26

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/15567887/execute-shell-script-everytime-a-new-user-is-created

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!