Lecture 15
User Management
User Types
o Super User
o Custom or Normal User
o System Users (no login)
Why multiple users?
User Directories and Files
User management basic commands
How to create users and passwords?
How to modify users?
How to delete users?
How to view and change users Password Policy?
How to switch between users?
How to give Super User privileges to Custom Users?
Copyright © Prof. TANVEER AHMAD
User Types
There are three types of users to work and manage Linux
Super User: A User with all the privileges to do anything
Custom or Normal User: Custom Users created for performing various
tasks
System Users (nologin): Built-in Users work in background (no need to
login)
Why Multiple Users?
Multiple users are created because of Security and Task Scheduling
Security: Multiple users can’t see other users files and can work securely
Task Scheduling: Many users can login at the same time to work
simultaneously
User Directories and Files
Super User Directory: /root
Custom User Directory /home
User IDs
Super User and Group IDs: UID = 0, GID = 0
System User and Group IDs: UID = 1-999, GID = 1-999
Super User and Group IDs: UID = 1000+, GID = 1000+
Super User: User file: /etc /root // contain all info about
root
Custom User: Users File /etc /passwd // contains all info about
custom users
Custom User: Passwords File /etc /shadow // contain all passwords of
custom users
Check and Edit Users and Password Files
# vim /etc /passwd // it will open users file to see and edit
users
Copyright © Prof. TANVEER AHMAD
Example Output for root user (root)
root :x :0 :0 :root :/root :/bin /bash
root -> username
:x -> mask password file which contain all passwords
:0 -> user ID
:0 -> group ID
:root -> user full name
:/root -> home directory
:/bin /bash -> shell type
Note the difference between the following two outputs at the end of output
lines
:/bin / bash -> it means user have a shell and can login to
system
:/sbin / nologin -> it means user do not have a shell and cannot login
Example Output for Custom user (Ahmad)
ahmad :x :1006 :1006 :tanveer ahmad:/home :/bin /bash
ahmad -> username
:x -> mask password file which contain all passwords
:1006 -> user ID
:1006 -> group ID
:tanveer ahmad -> user full name
:/home -> home directory
:/bin /bash -> shell type
# vim /etc /shadow // it will open password file to see and edit
passwords
Example Output for root user (root)
root :x :$ - - - - - :0 :9999 :7 ::::
root -> username
:$ - - - - -> it shows the password is encrypted
:0 -> Minimum Expiry Days
Copyright © Prof. TANVEER AHMAD
:9999 -> Maximum expiry Days
:7 -> Change password Alert
Example Output for Custom user (Ahmad)
ahmad :x :$ - - - - - :0 :9999 :7 ::::
ahmad -> username
:$ - - - - -> it shows the password is encrypted
:0 -> Minimum Expiry Days
:9999 -> Maximum expiry Days
:7 -> Change password Alert
User management basic commands
# whoami -> to check current user details
# id -> to check user ID
# who -> to check current user logged in to system
#w -> it shows the system hardware status
# last -> it shows when system is rebooted last time
# system-config-users -> users and groups management by GUI
interface
# init 0 -> shutdown system
# init 6 -> restart system
How to create users and passwords?
# useradd user1 -> it will create user with username User1
# vim /etc /passwd -> to check the username is created in the users file
# useradd –c “Tanveer Ahmad” ahmad -> it will create user ahmad with
full name
# vim /etc /passwd -> to check the username is created in the users file
# mkdir CustomUsers -> it will create a user define directory to
store users
# useradd –d /CustomUsers /username -> it will create a user inside directory
CustomUsers
# useradd –s /sbin /nologin ali -> it will create a user ali but can’t login
# su username -> to switch user #exit -> to exit
from user
# su - username -> to forcefully switch user to its default
directory
Copyright © Prof. TANVEER AHMAD
# passwd Press-enter -> it will ask for new password to change
# passwd username -> to set the password for user
# passwd –l username -> to lock the password for user
# passwd – u username -> to unlock the password for user
# tail /etc /shadow -> to check passwords and related info (last
10 users)
How to modify users?
# usermod –c “Ali Raza” ali -> it will modify user ali with full name
# vim /etc /passwd -> to check the username is created in the users file
# usermod –L user1 -> it will lock the user (error. User Authentication
Fail)
# ls –l /home -> to check the username is deleted from the users
file
# usermod –U user1 -> it will un-lock the user back to work
# vim /etc /passwd -> to check the username is deleted from the users
file
# usermod -u 1020 username -> to change the user ID to new ID
# id username -> to verify the user ID is changed
How to delete users?
# userdel user1 -> it will delete user1- only user deleted not directory
# vim /etc /passwd -> to check the username is deleted from the users file
# ls –l /home -> it will still shows the user directory exists
# userdel –r user1 -> it will delete user1also delete user directory
# vim /etc /passwd -> to check the username is deleted from the users
file
# ls –l /home -> it will not show the user directory
How to view and change users Password Policy?
# chage -l user1 -> it will show password details or password policy
# chage user1 -> it will give you facility to change password policy
How to Switch between users?
# su -> it will switch to root user by default
# su - -> it will switch to user with default directory
# su - username -> it will switch to any user with its default directory
How to give Super User privileges to Custom Users?
# vim /etc /sudoers -> it will change settings in sudoers file to use SUDO
command
root ALL = (ALL) ALL -> Existing output line in the file
user1 ALL = (ALL) ALL -> New line added to the file for
Copyright © Prof. TANVEER AHMAD
permission to user1
[user1@localhost ~]$ sudo passwd user6
-> now user1 can change the password for any user without root user
permissions
Copyright © Prof. TANVEER AHMAD