Table of contents
User Management in Linux:
User addition
User deletion
User restriction
Setting password policy
Whenever a user is created in Linux following directories have new entries in them:
/home: User home directory is created under /home directory
/etc/passwd: file represents an individual user account and contains the following seven fields separated by colons (:). It is owned by root and has 644 permissions. The file can only be modified by root or users with sudo privileges and is readable by all system users.
/etc/shadow: This is where the user password is stored in encrypted format [SHA512 ($6), SHA256 ($5), MD5 ($1)]
/etc/group: Whenever a user is created a corresponding group is created with the same name as the user name.
/etc/gshadow: Group password is stored
You can create Users in Linux in the terminal
User addition:
useradd
useradd Ram
the command "useradd" is used to create a user Ram in Linux
How to Change Passwords in Linux?
passwd
Use “passwd” command to set, and change password for Users in Linux.
passwd
Type your password
Type new password
Retype the new password
You can use different options along with “passwd” command for different scenarios.
- You can also enforce passwords in Linux:
passwd –e usrname
-e: Option will enforce the user to reset his password
- You can lock the User:
passwd –l usrname
-l: Option will lock the user account by changing the password to a value that matches no possible encrypted value.
- You can unlock the User:
passwd –u usrname
-u: Option will unlock the user's password
Note:
/usr/sbin/useradd: Binaries for useradd command are stored here
We can give non-interactive Shell to an User: /sbin/nologin
We can give interactive Shell to an User: /bin/bash
Every task performed by sudo user is recorded in: /var/log/secure
/etc/sudoers: Very important file
/etc/skel: All files from this directory are copied to a user’s home directory
How to change Home directory of a user?
By making changes in file as shown below
/etc/default/useradd
How to add 100s of Users with the same password expiry date?
By making changes in in file as shown below
/etc/login.defs
What happens if the user’s home directory is deleted?
The user won’t have a Shell anymore.
How to delete a User?
userdel -r Satish
-r: Option is used to delete home dir along with the User
How to delete a Group?
groupdel Sales
groupdel HR
How to modify a user/add a user to a group?
usermod -aG IT, Admin, DevOps
How to remove a user from the group?
gpasswd -d Satish Admin