0

When I create a user with useradd (no option) I can later add his passwd by using passwd new_user.

How can I create his correct home directory (with Desktop and Templates inside) and all other parameters the user needs?

I mean how can I obtain the equivalent of adduser?

1

1 Answer 1

0

You can use usermod to modify an existing account. However this will not populate the user's HOME directory as useradd --create-home does.

Instead, you have to do it yourself.

# Consider a user 'fred' user=fred skel=$(. /etc/defaults/useradd 2>/dev/null; echo "$SKEL") home=$(getent passwd "$user" | cut -d: -f6) gid=$(getent passwd "$user" | cut -d: -f4) mkdir -p -m755 "$home" cp -a "${skel:-/etc/skel}/." "$user" chown -R "$user":"$gid" "$home" 

Missing XDG directories will be created as the user first logs in.

7
  • I get errors on --> cp -a "${skel-/etc/skel}/." "$user" ... Commented Sep 13, 2018 at 7:22
  • @pietroletti found it. Mobile phone typo. Sigh. Commented Sep 13, 2018 at 7:58
  • what's the utility of the simple command: useradd new-user if I can't populate the home directory later? Commented Sep 14, 2018 at 8:20
  • @pietroletti why wouldn't you want to populate the home directory when you created the user with useradd? Commented Sep 14, 2018 at 8:56
  • that's just curiosity: if a command exist it should be for something -> if I do useradd new_user the system add a new user -> what's for if it's not directly possible to add a home to that user? --> what else I can do with a user who has not a home directory? Commented Sep 14, 2018 at 18:15

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.