3

If I, as a root user, add user milos, then the system asks me to provide some info, which I do.

When I, after that, userdel milos, it removes it and removes milos group.

Now, if I'm to useradd milos again, it doesn't ask me for a user password nor any info about the user whatsoever.

What did these commands do? How can I properly remove a user?

5
  • 2
    adduser is different from useradd. Apr 7, 2017 at 21:48
  • use the -r flag when removing a user to ensure that the home directory and mail spoolers have been removed
    – Gansheim
    Apr 7, 2017 at 21:52
  • Did that, no help. It only complains /home/milos is not found and something regarding mail accounts.
    – Milos
    Apr 7, 2017 at 22:06
  • @AndroidDev how so?
    – Milos
    Apr 7, 2017 at 22:06
  • @muru no, it's not duplicate. Also, this is better described, goes far more in-depth.
    – Milos
    Apr 8, 2017 at 16:03

1 Answer 1

8

The adduser and useradd commands work differently.

useradd user_name

Simply creates the user. It doesn't even ask you for a new password. It also does not create the home directory for this user. All these things you have to do manually after creating the user.

OR you can tell it when running the useradd command. For example, the command useradd -d /home/username -m username, includes creation of a home directory for this user.

Set the password after creating user, by passwd username.

adduser

root@ubuntu-server:~# adduser username
Adding user `username' ...
Adding new group `username' (1006) ...
Adding new user `username' (1006) with group `username' ...
Creating home directory `/home/username' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for username
Enter the new value, or press ENTER for the default
Full Name []: User name
Room Number []: 405
Work Phone []: 555-412-5555
Home Phone []: 412-555-5555
Other []: 
Is the information correct? [Y/n] y

The adduser command does everything automatically for you as shown here.

The adduser command is much more convenient for creating users. The reason useradd is provided even when there is adduser is that not all distributions come with adduser.

Not the answer you're looking for? Browse other questions tagged or ask your own question.