Automatically create a folder after creating the user

Hello and do not be tired

How to create a directory for a user automatically after creating a new user?

For example, after creating a user, a directory with a username is created in the / mnt / sda1 folder.

I am using an adduser


Solution 1:

From man adduser

If the file /usr/local/sbin/adduser.local exists, it will be executed after the user account has been set up in order to do any local setup. The arguments passed to adduser.local are: username uid gid home-directory.

So, you can create the file and add a simple script, e.g.:

#!/bin/sh
# This script is executed at the end of adduser
# USAGE:
# adduser.local USER UID GID HOME

mkdir "/mnt/sda1/$1"
chown $2:$3 "/mnt/sda1/$1"

Not sure, but you might need to make the script executable:

sudo chmod +x /usr/local/sbin/adduser.local