Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to create or delete user in Linux

📅 2018-Jul-13 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ user ⬩ 📚 Archive

There are 2 commands in a modern Ubuntu to create new users: adduser and useradd. Unless you know what you are doing, do not use useradd.

adduser (USE THIS)

$ sudo adduser joe

This creates a normal user, creates their home directory, copies over the dot files from /etc/skel, requests you to set the password for this user and generally sets up everything for the user to login and use the shell.

In addition, if you also want the user directories like Desktop, Downloads and such to be created:

<login as joe>

$ xdg-user-dirs-update
$ sudo useradd joe

This command does not even create a home directory for the new user.

$ sudo useradd -m joe
$ sudo userdel joe

The above command does not remove the files owned by the user.

$ sudo userdel --remove-all-files joe

References:

Tried with: Ubuntu 22.04


© 2023 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧