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.

  • 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

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.

username=$1 uid=$2 gid=$3 home_dir=$4
if [ -d "$home_dir/MyStevedore" ]; then
  chgrp stevedore "$home_dir/MyStevedore"
| improve this answer | |

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.

| improve this answer | |

Your Answer

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

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