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?

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.

  • I get errors on --> cp -a "${skel-/etc/skel}/." "$user" ... – pietro letti Sep 13 '18 at 7:22
  • @pietroletti found it. Mobile phone typo. Sigh. – roaima Sep 13 '18 at 7:58
  • what's the utility of the simple command: useradd new-user if I can't populate the home directory later? – pietro letti Sep 14 '18 at 8:20
  • @pietroletti why wouldn't you want to populate the home directory when you created the user with useradd? – roaima Sep 14 '18 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? – pietro letti Sep 14 '18 at 18:15

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.