useradd command examples

– To create/add new users into the system, Linux has a useradd command.

– useradd provides many options for creating users, we can create local, system or superusers using it.

– It comes from “shadow-utils-” package, we have covered almost all the options here.

1. Adding the user with the default settings

                 # useradd mike 
2. To add the user with mentioning comments

                 # useradd -c “Anything” mike 
3. To add user with mentioning home directory

                 # useradd -d /tmp/mike mike 
4. To add user with expiration date

                 # useradd -e 2013-12-31 mike 
5. To add user account with number of days of inactivity

                 # useradd -f 2 mike 
6. To add user with specifying primary group to it

                 # useradd -g UNIX mike 
7. To add user with  mentioning secondary groups to it

                 # useradd -G Support, IT mike 
8. To add user while home directory will not be created for it

                 # useradd -M mike 
9. To create a user with duplicate UID

                 # useradd -u 500 -o mike 
10. To create a system account

                # useradd -r mike 
11. Creating user with assigning specific shell to him

                # useradd -s /bin/bash mike 
12. Creating user with particular user ID

                # useradd -u 521 mike 

Related Commands: chfn, chsh, passwd, crypt, groupadd, groupdel, groupmod, login.defs, newusers, userdel, usermod.

Leave a Reply

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