Adding Users in Linux
This short tutorial shows you how to add Linux user using CLI.
useradd Command Syntax
You can add users using useradd command.
Usage: useradd [options] LOGIN
Options:
-b, --base-dir BASE_DIR base directory for the home directory of the
new account
-c, --comment COMMENT GECOS field of the new account
-d, --home-dir HOME_DIR home directory of the new account
-D, --defaults print or change default useradd configuration
-e, --expiredate EXPIRE_DATE expiration date of the new account
-f, --inactive INACTIVE password inactivity period of the new account
-g, --gid GROUP name or ID of the primary group of the new
account
-G, --groups GROUPS list of supplementary groups of the new
account
-h, --help display this help message and exit
-k, --skel SKEL_DIR use this alternative skeleton directory
-K, --key KEY=VALUE override /etc/login.defs defaults
-l, --no-log-init do not add the user to the lastlog and
faillog databases
-m, --create-home create the user's home directory
-M, --no-create-home do not create the user's home directory
-N, --no-user-group do not create a group with the same name as
the user
-o, --non-unique allow to create users with duplicate
(non-unique) UID
-p, --password PASSWORD encrypted password of the new account
-r, --system create a system account
-s, --shell SHELL login shell of the new account
-u, --uid UID user ID of the new account
-U, --user-group create a group with the same name as the user
-Z, --selinux-user SEUSER use a specific SEUSER for the SELinux user mapping
Command Usage
To add an user account use the command below.
Note : You must be logged in as root user (or use “sudo su” command)
Add user named testuser01 with “Test User 1″ as its “Display Name”
-m switch will create user’s home directory
root@ubuntu:~# useradd -c "Test User 1" -m testuser01
Now set the password for user account
root@ubuntu:~# passwd testuser01 Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully root@ubuntu:~#
Verification
Check if the newly created user is in the passwd file
root@ubuntu:~# tail -n 1 /etc/passwd
testuser01:x:1001:1001:Test User 1:/home/testuser01:/bin/sh
The password is stored as SHA512 format in shadow file
root@ubuntu:~# tail -n 1 /etc/shadow
testuser01:$6$9R0tTLo7$ZD32rIGGbUTac0Ump7JL.O18tUIoNRtvSYTuwao0Pe7ZFqiKwk3nnbR5PWU4w1an7MgCdmVouHkj.d0soyYka1:15108:0:99999:7:::
Verify that the home directory exists
root@ubuntu:~# ls /home
test testuser01
Summary
This tutorial covered basics of user creation in Linux with appropriate home directory. I have used Ubuntu for this demo, but this same commands can be used in any other distributions.
| This entry was posted by Arsalan A. Suzuki on May 14, 2011 at 2:20 pm, and is filed under Linux. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
