Score:3

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

Paul avatar
us flag
Do you mean the user home directory?
pasman pasmański avatar
mx flag
@ahmadreza There are many methods to create user. Which you use?
hr flag
If you use `adduser` to create the user, then you should be able to perform additional post-creation tasks via a `/usr/local/sbin/adduser.local` script
@steeldriver That's right I'm using an adduser
Score:3
in flag

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
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.