0

I want to run a script with sudo privileges when a new user is added to my system. More specifically, whenever I create a new user (with useradd or adduser), I want to be able to create a folder outside the user's home directory, under a directory owned by root (this would a shared HDD). is there a way to do this systematically so I don't have to manually create a folder for each user I add to my system? I know I can customize the user's home enviroment my changing the files/directories in /etc/skel but I want to be able to assign a shared folder to the new user elsewhere, and named it "${USER}_data"

I tried adding a simple mkdir path_to_rootDir/${USER}_data command in different system-wide initialization files (/etc/.profile, /etc/.bashrc), but it always fails to create the directory because it is not run as root (permission denied).

4
  • 1
    Usual way would be to create a script e.g. myuseradd.sh which performed the useradd and also the mkdir aspect.
    – steve
    Sep 26 '20 at 13:22
  • I am confused. I can not find the connection between the title and the body of this question: The title seems to be about sudo, the body seems to be about creating a user. Sep 26 '20 at 17:09
  • I expanded my question, hopefully this make sit more clear. @steve Could you expand on this? is there any way to just configure the adduser command to create a additional folder(s) - besides the home directory - outside the user's home? Sep 28 '20 at 22:29
  • You could achieve this using pam_exec, e.g. unix.stackexchange.com/questions/449845/…
    – steve
    Sep 29 '20 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.