Creating User Acount in CentOS /Red Hat /Fedora Linux

To Add a new user in CentOS /Red Hat  you use ‘ useradd ‘ command as a root .By default useradd command creates a locked user account. To unlock the User account, run the ‘passwd’ command as a root to assign a password. 

The syntax to Create or Add User In Linux:

useradd [options]  User_Name

Create a User John with the Home directory :

[root@localhost ~]# useradd -m John
[root@localhost ~]#

To Set Password for User John with the ‘ passwd ‘ command:


[root@localhost ~]# passwd John
Changing password for user John.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]#

To change User default home directory : 

By default home directory in linux is ‘/home/username/ ‘. you can change the default home directory path and directory name with ‘-d ‘ option with the ‘ useradd ‘command


[root@localhost ~]# useradd -m -d /usr/my_home Johny
[root@localhost ~]# passwd Johny
Changing password for user Johny.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# ls /usr
bin  etc  games  include  lib  lib64  libexec  local  my_home  sbin  share  src  tmp
[root@localhost ~]#

User Default login Shell :

By default login shell in Linux is  ‘/bin/bash ‘ .To check Installed Shell on your system  type the’ chsh -l ‘ command on the shell prompt


[root@localhost ~]# chsh -l
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
/bin/tcsh
/bin/csh
[root@localhost ~]#


If you want to make default login shell  ‘ /bin/tcsh ‘ for user noor 


[root@localhost ~]# useradd -m -s /bin/tcsh noor
[root@localhost ~]#


To check the login shell for user ‘ noor ‘ you use the ‘ ps -p $$ ‘command.


[root@localhost ~]# su noor
[noor@localhost /root]$ ps -p $$
PID TTY          TIME CMD
7064 pts/0    00:00:00 tcsh
[noor@localhost /root]$


To add a user in a group :


To add a user Bil in a Developer group you use ‘ -G ‘ option with ‘ useradd ‘ command


[root@localhost ~]# useradd -G developer -m Bil


To check the user Bil Group you use following commands


[root@localhost ~]# su Bil

[Bil@localhost root]$ id -Gn Bil
Bil developer
[Bil@localhost root]$ groups Bil
Bil : Bil developer
[Bil@localhost root]$

All command line options  used with the useradd command are shown below

_____________________________________________________________________________

               Option                                                                Description

______________________________________________________________________________

   -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 to be used instead of 

                              default /home/username/

  -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

  -R, –root CHROOT_DIR                     Directory to chroot into

  -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



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s