Three tools for creating users in Debian based distros: useradd, adduser and newusers

The three commands for creating users in Debian based Linux distros are useradd, adduser and newusers.

The generical useradd command:

The useradd command is universal, the same for all the Linux distributions. I wrote an article about the useradd command here.

The adduser command:

The adduser command is userfriendly and interactive.

Syntax: adduser username

$ sudo adduser deb
Adding user `deb' ...
Adding new group `deb' (1013) ...
Adding new user `deb' (1011) with group `deb' ...
Creating home directory `/home/deb' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for deb
Enter the new value, or press ENTER for the default
Full Name []: deb
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y

You are given a UID (the first one available), added to a group with the same name as your new user, created and assinged a homedir (/home/username), you get the data from the /etc/skel directory copied in your ~ , asked to insert a password (twice), to fill in some extra information (you can skip by pressing 5 times enter) and at the end, asked to confirm. (Y is Yes and N is no)

$ grep deb /etc/passwd
deb:x:1011:1013:deb,,,:/home/deb:/bin/bash

And it worked.

The newusers command:

The newusers command is usefull when you have to add (or update) an entire list of users. And it is very simple to use.

Syntax: newusers filewithusers

The file that contains the “to be added users” has the same structure as the /etc/passwd file.

structure: username:password:user_id:group_ip:other_info:homedir:login_shell .

I often fill in only the username,password and the login shell (and get the UID and GID by default). Like this:

$ cat filewithusers
wolverine:passwd1::::/home/wolverine:/bin/bash
xavier:passwd2::::/home/profesorx:/bin/bash
storm:passwd3::::/home/preetystorm:/bin/bash
$ sudo newusers filewithusers
$ tail -3 /etc/passwd
wolverine:x:1013:1015::/home/wolverine:/bin/bash
xavier:x:1014:1016::/home/profesorx:/bin/bash
storm:x:1015:1017::/home/preetystorm:/bin/bash

The passwords for the new users are the ones written in the list. But in /etc/shadow they are stored in a crypted format.

Example of /etc/shadow line:

$ sudo grep wolverine /etc/shadow
wolverine:$6$UrlyPx/N$dNiCn/h.LFVicZ5g6FBvYlz63lDRgou5Hc278Gwy8Tp7XomcmiDsDToVjBIJTXe/exoF06MbhxQUgaKzA.7Od/:15485:0:99999:7:::

The username, homedir, login shell and the other user info can be manually modified (as root) by editing the /etc/password file, or with the usermod command combined with the proper options.

Share and Enjoy

  • Twitter
  • Facebook
  • Google Plus
  • Email
  • RSS
Tagged with: , , , , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Subscribe

  

Subscribe to get the latest Linux news and how to guides directly on your e-mail!