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).
myuseradd.sh
which performed theuseradd
and also themkdir
aspect. – steve Sep 26 '20 at 13:22sudo
, the body seems to be about creating a user. – ctrl-alt-delor Sep 26 '20 at 17:09adduser
command to create a additional folder(s) - besides the home directory - outside the user's home? – ricardo3889 Sep 28 '20 at 22:29pam_exec
, e.g. https://unix.stackexchange.com/questions/449845/using-pam-exec-so-to-run-a-script-as-root-when-a-user-logs-in-while-extracting – steve Sep 29 '20 at 17:58