create default folder structure and ownership on user creation

Dear Experts,

I'm involved in a rather big project and I'm trying to automate as much of it as possible.
The problem I'm tackling right now consists of the following.
Assume I have a web interface that accepts a domain (for this example, we shall use banana.com)
the web interface then removes any dots, hyphens or any other special character from the domain name and passes the resulting string as a parameter to a bash script, which in turn invokes the useradd command.
so in this case, the command will be invoked as
useradd -m bananacom

Open in new window


This is all good and well and works fine.
I have also modified the /etc/skel folder to automatically create public_html and tmp folders in each users home directory.
Since we are using a very heavily customized NGINX version (Running on Centos 7) I need that everything under /home/$user/public_html (including the public html folder itself)
will always be set to 750 permissions, and $user:nginx ownership.

Meaning the as soon as I cerated the user, if I'd go to /home/bananacom
I'd see 2 folders in it:
/home/bananacom/public_html
/home/bananacom/tmp
Both will have drxw for bananacom, r-x for nginx and --- for other.
also, I need anything created under the public_html to defualt to those settings as well.
How would I go about creating such a thing?
LVL 8
David SankovskySenior SysAdminAsked:
Who is Participating?
 
serialbandCommented:
I believe you just need to set the default umask as 0027 for all users and they should be set correctly.
0
 
David SankovskySenior SysAdminAuthor Commented:
This will help with the permission Settings.
I still need to know how to set the default ownership.
Seeing as I need the skeleton to be created with nginx as the group
0
 
huacatCommented:
# please create other folders first before below commands!
# set ownership command:
chown -R bananacom:nginx /home/bananacom/
# set permission command:
chmod -R 750 /home/bananacom/
0
 
David SankovskySenior SysAdminAuthor Commented:
That worked better than expected Thank you
0
 
serialbandCommented:
Did you mean to give me all the points?  If you meant to split the points I can request attention and let you divide it properly.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.