Skip to content

Instantly share code, notes, and snippets.

@AjeetK
Last active July 10, 2024 16:57
Show Gist options
  • Save AjeetK/25c0b73b0ef8bc01d979d4702c22ff9a to your computer and use it in GitHub Desktop.
Save AjeetK/25c0b73b0ef8bc01d979d4702c22ff9a to your computer and use it in GitHub Desktop.
User Management in Linux

Types of user:

  1. Root User - It is the super user which can run any command generally used for administration.
  2. System User - Users needed for system specific operation/components, like mysql user to run mysql.
  3. Normal User - Other users which are created by root and have limited access given to them.

Attributes:

  1. User Type: Super user
  2. User Name: root
  3. User ID: 0
  4. Group ID: 0
  5. Home Directory: /root
  6. Shell: /bin/bash

Video Tutorial

User Management In Linux

Important Files:

  1. /etc/passwd - Keeps user account and password information.
  2. /etc/shadow - Keeps the encrypted password of the corresponding account

Creating a User:

1. Add a user:
	 # useradd user1
2. Assign a password to a created user:
	 # passwd user1
3. Create user with account expiry date:
	 # useradd -e 2018-04-01 user2
4. Create a user with specific user id
	 # useradd -u 5111 user3
5. Create a user with specific user id and group id (Group Id must be present already)
	 # useradd -u 6111 -g 1000 user4
6. Add user to Multiple groups (user5 is being created and added to sudo and user1 group)
	 # useradd -G sudo,user1 user5
7. Add user with comments:
	 # useradd -c”Deverloper” user6
	 # tail -1 /etc/passwd 
8. Add user with home directory
	 # useradd -m -d /home/user7 user7
	 # tail -1 /etc/passwd

Deleting a User:

1. Deleting existing user:
	 # userdel user1
2. Delete user forcefully, even if the user is logged in
	 # userdel -f user2
3. Delete user with home directory
	 # userdel -r user7

Modify User Property:

1. Changing home directory of a user:
	 # useradd -d /home/user7 user7
	 # usermod -d /home/appychip user7
2. Changing Primary group of a user:
	 # usermod -g sudo user4
3. Lock(-L) and Unlock(-U) users
	 # usermod -L  user5
	 # usermod -U user5
	 Verify in /etc/shadow if an ! mark is present in front of user name. If present then user is locked.
	 After unlock it will disappear
4. Changing login name and password (xyz is new username and user6 is existing user)
	 # usermod -l xyz user6
	 # usermod -p p@ssWord xyz
5. View Account raging information:
	 # chage -l xyz
6. Changing password parameters:
	 # chage xyz
	 Enter a new value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment