Skip to content

Latest commit

 

History

History
145 lines (104 loc) · 1.89 KB

File metadata and controls

145 lines (104 loc) · 1.89 KB

User Management Commands for Beginners

Show current user

whoami

Show details of current user

id

Become root user

sudo su -

Add a new user with home directory

sudo useradd -m username

Create home directory automatically

sudo mkhomedir_helper username

Set password for a user

sudo passwd username

Switch to another user (login shell)

su username

Delete a user

sudo userdel username

Create a new group

sudo groupadd groupname

Add user to a group

sudo usermod -aG groupname username

Delete a user from group

sudo gpasswd -d username groupname

Delete a group

sudo groupdel groupname

Change file owner

sudo chown username file.txt

Change file owner and group

sudo chown username:groupname file.txt

Lock a user account

sudo usermod -L username

Unlock a user account

sudo usermod -U username

Understanding the Shadow File (Password & Account Status)

What is /etc/shadow?

  • Stores encrypted passwords
  • Contains password expiration info
  • Only accessible by root

View Shadow File (Root Only)

sudo cat /etc/shadow

Format of /etc/shadow

Example entry:

username:$6$abc123xyz$hashedpassword:19000:0:99999:7:::

It contains 9 fields separated by :

username:password:lastchg:min:max:warn:inactive:expire:reserved

How to Check If Password is Set or Not

If password field contains:

  • !! → User has no password set
  • ! at beginning → Account is locked
  • $6$... → Password is set (hashed)

Example:

john:!!:...

👉 Password NOT set

john:!$6$abc123...

👉 Account LOCKED

john:$6$abc123...

👉 Password is SET and account is active