User Management in Linux

User Management in Linux

User Management in Linux:

  1. User addition

  2. User deletion

  3. User restriction

  4. Setting password policy

Whenever a user is created in Linux following directories have new entries in them:

  1. /home: User home directory is created under /home directory

  2. /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.

  3. /etc/shadow: This is where the user password is stored in encrypted format [SHA512 ($6), SHA256 ($5), MD5 ($1)]

  4. /etc/group: Whenever a user is created a corresponding group is created with the same name as the user name.

  5. /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.

  1. You can also enforce passwords in Linux:
passwd –e usrname

-e: Option will enforce the user to reset his password

  1. 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.

  1. You can unlock the User:
passwd –u usrname

-u: Option will unlock the user's password

Note:

  1. /usr/sbin/useradd: Binaries for useradd command are stored here

  2. We can give non-interactive Shell to an User: /sbin/nologin

  3. We can give interactive Shell to an User: /bin/bash

  4. Every task performed by sudo user is recorded in: /var/log/secure

  5. /etc/sudoers: Very important file

  6. /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