Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I d like to set the home directories permissions as 755 when i add the user via useradd.

How can i do this?

Thanks.

share|improve this question
add comment

4 Answers 4

up vote 4 down vote accepted

Look at the UMASK parameter in /etc/login.defs:

UMASK (number) The permission mask is initialized to this value. It is used by useradd and newusers for creating new home directories. If not specified, the permission mask will be initialized to 0077.

(from man login.defs)

This is a mask, so the default of 0077 will give you home directory permissions 700, 0022 will give 755.

Interestingly, OpenSuse uses 0022 by default.

If you want to change the default permissions for the files your users create in their home directories, you need the umask command. This can be run from /etc/profile for example.

share|improve this answer
    
using the /etc/profile or /etc/bashrc as mentioned, it's also best to restrict things to a certain group of users (mainly so that you don't screw up root), ala: if [ id -gn = mygroup ]; then umask 0002 fi This would set all members of 'mygroup' to have 0775/0664 perms upon login, handy for dev servers where code is shared by a group of engineers. –  troyengel Jan 2 '10 at 20:13
    
this works :) great. thanks. –  user30597 Jan 2 '10 at 20:36
add comment


I believe this is the answer for your question :

/etc/login.defs

here you can define default values for useradd.

--
Regards,
Robert

share|improve this answer
    
If this is not the way you wanted then probably only some shell script will resolve your prorblem. –  Robert Jan 2 '10 at 19:38
add comment

You could write a wrapper utility script that calls both useradd and chmod.

But why would you want this? People expect /home/username to be private. It probably would be better to give a separate, shared directory to each user.

share|improve this answer
    
:) I m aware of suggestion. I just want to do it like this for some purpose. sorry but i dont like the script idea. –  user30597 Jan 2 '10 at 19:07
add comment

You could use ''adduser'' after editing the /etc/adduser.conf file and setting DIR_MODE=0755. That's opposed to ''useradd'' There are various customisations that you can do in /etc/adduser.conf.

What linux are you using. Ubuntu has ''adduser''.

share|improve this answer
    
I d like to do it on Centos for now. Thanks. –  user30597 Jan 2 '10 at 20:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.