Basic Linux Commands: The adduser Command

Basic Linux Commands: The adduser Command
Page content

Is it “useradd” or “adduser”?

In the beginning the UNIX command was useradd. Somewhere along the line the command changed to adduser. In some flavors of Linux the useradd command has been dropped in favor of adduser. In some flavors of Linux however, both commands remain. In fact, if you are using certain Linux distributions (such as Mandriva) you can issue either man useradd or man adduser - both commands come up with the useradd man page. Thus useradd and adduser are essentially the same command.

So depending upon your distribution, you will either use adduser or useradd. If you try to use one and you receive “command not found”, just use the other. Simple.

Basic usage

First and foremost, adduser can only be used by the root user. What this command does is add a new user to a system. It’s fairly straight-forward and simple. Once you have root privileges (which can be either through su or sudo) at a bash prompt (using a terminal such as aterm, gnome-terminal, or konsole) the adduser command looks like this:

adduser [options] USERNAME

Where USERNAME is the actual name the user will log in with.

There are a number of options to be used with this command. The more important options are:

  • d - This argument creates the home directory for the new user. You should define the new users home directory as their log in name. So if you use maryjane as your user login, the home directory will be /home/maryjane and the command would look like useradd maryjane -d /home/maryjane.
  • m - If you have already created a user but failed to add a home directory, you can issue this argument with useradd (followed by the username) to create a home directory for the user.
  • p - This will allow you to define the users password. The p argument is always followed by the actual password for the user. So, to add on to the above command, adding the user maryjane with a home directory of /home/maryjane and a password of 1mary2jane3, you would issue the command useradd maryjane -d /home/maryjane -p 1mary2jane3.

Final Thoughts

To any Linux administrator, having the adduser command available is an absolute necessity for so many tasks (adding users for mail servers, log ins, etc. The useradd command is simple to use but is often overlooked. If you have a gui-less server you will have to know how to add users via the command line.

This post is part of the series: Linux Command Line

If you ever plan on doing any administration on a Linux machine, you would be well served to get to know the command line interface. In this Bright Hub series you will be introduced to various concepts surrounding one of the most powerful admin tools around.

  1. Linux Command Line: Introduction
  2. Linux Command Line: ls
  3. Linux Command Line: cd
  4. Linux Command Line: mkdir
  5. Linux Command Line: df
  6. Linux Command Line: ln
  7. Linux Command Line: top
  8. Linux Command Line: mount/umount
  9. Linux Command Line: Cron/Crontab
  10. Linux Command Line: chmod
  11. Linux Command Line: wget
  12. Linux Command Line: cat
  13. Linux Command Line: grep
  14. Linux Command Line: dd
  15. Linux Command Line: sudo
  16. Linux Command Line: startx
  17. Linux Command Line: adduser
  18. Linux Command Line: at
  19. Linux Command Line: aterm
  20. Linux Command Line: nano
  21. Linux Command Line: hostname