Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Linux will copy the the contents of /etc/skel when a new user is created. I want to have a sub-directory in each user's home directory, MyStevedore. I want this directory to have the owner be the new user and the group to be the group stevedore with the permissions drwxrwxr-x. The user is not a member of the group stevedore.

share|improve this question

migrated from serverfault.com Feb 13 '11 at 8:34

This question came from our site for professional system and network administrators.

1  
what Linux distribution are you running? –  Ash Palmer Oct 27 '10 at 20:04
2  
And the reason the distro matters is because depending on the distro and how you are creating users there are methods to extend the user creation tools to run a script of your choosing. For example on Debian-based systems /usr/local/sbin/adduser.local will be called when you run adduser to create an account. –  Zoredache Oct 27 '10 at 20:17
    
this is where a little script-fu wrapped around useradd might do the trick. Certain other distro's have 'adduser' which is a bash script doing just that! –  Ash Palmer Oct 27 '10 at 20:30
add comment

2 Answers 2

Assuming you're using adduser to create the user, it will do most of the job, assuming you've created a directory /etc/skel/MyStevedore with your desired permissions. However on most systems ~/MyStevedore will always belong to the user's primary group.

On Debian and derivatives (including Ubuntu), once adduser has created the user, it calls /usr/local/sbin/adduser.local if it exists. You can use it to complete the job.

#!/bin/sh
username=$1 uid=$2 gid=$3 home_dir=$4
if [ -d "$home_dir/MyStevedore" ]; then
  chgrp stevedore "$home_dir/MyStevedore"
fi
share|improve this answer
add comment

You could add an if statement to the .bash_profile script in /etc/skel that will check if the folder exists. If it doesn't exist it will create it and set the permissions.

The first time a new user logs in the folder will be created.

share|improve this answer
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.