Loading...
Linux Interview Questions

User Administration

User Administration

1 .Where are user details stored in Linux?
A) In /etc/passwd (basic account info) and /etc/shadow (password hashes & aging).

2. How to set a username and password to NEVER EXPIRE?
A) To set a Linux user account and password to never expire, we use the chage command.
For example:
→ password never expires

chage -M 99999 username

→ account never expires

chage -E -1 username

We can verify Password expiry details using

chage -l username

.

3. Why are /etc/passwd and /etc/shadow not merged into one file?
A)

  • /etc/passwd contains general user account information and must be world-readable so that processes and commands can map UIDs to usernames.
  • /etc/shadow contains sensitive password hashes and aging details, which must be protected.
    If they were merged, either:
  • The whole file would need to be world-readable (insecure), OR
    restricted to root (then many system utilities would break).
    That’s why Linux keeps them separate balancing usability and security.

4.How do you give sudo access to a user?
A) Add user to wheel or sudo group, OR
Edit sudoers file with visudo

username ALL=(ALL) NOPASSWD:ALL

5.How do you check which users are logged in?
A)

who
w

6.How do you switch to another user account?
A)

su - username

7.How do you check a user’s UID, GID, and groups?
A)

id username

8. A user complains they cannot log in. How will you troubleshoot?
A)

  • Check if user exists in /etc/passwd
  • Check if account locked → passwd -S username
  • Check expiry → chage -l username
  • Check shell → bin/bash or /sbin/nologin
  • Check home directory permissions
  • Check logs → /var/log/secure or /var/log/auth.log
  • Reset password if needed

9.How do you lock/unlock a user account?
A)

usermod -L username
usermod -U username

10.How do you force a user to change password at next login?
A)

passwd -e username

11.How do you add a user to a secondary group?
A)

usermod -aG developers username

12.How do you delete a user and their home directory?
A)

userdel -r username

13.How do you check last login history of a user?
A)

last username

14. A user’s home directory is missing. How will you restore it?
A)Verify the user entry in

grep '^username:' /etc/passwd

Check if directory exists

ls -ld /home/username

Recreate the home directory

mkdir /home/username
cp -r /etc/skel/* /home/username/
chown -R username:username /home/username
chmod 700 /home/username*

Optional – recreate automatically with usermod

usermod -m -d /home/username username

Test login

su - username

15. A user was added to sudoers but sudo still doesn’t work .what could be wrong?
A) Check if user is really in sudoers file

sudo -l -U username

If it says “user is not allowed to run sudo”, the entry in /etc/sudoers might be wrong.
Check if the syntax in /etc/sudoers is valid

visudo

If you directly edit /etc/sudoers and make a syntax error, sudo won’t work.
Correct entry format:

username ALL=(ALL) ALL

Check if user is in the correct group

groups username

should show sudo.
If missing → add them

usermod -aG wheel username

Then check in /etc/sudoers

%wheel ALL=(ALL) ALL

Check sudo package is installed Some minimal installs don’t include sudo

which sudo

If not found

yum install sudo

Check permissions on/etc/sudoers
They must be

ls -l /etc/sudoers
-r--r----- 1 root root /etc/sudoers

If wrong, fix

chmod 440 /etc/sudoers
chown root:root /etc/sudoers

Check if user is logging in with correct account
Sometimes user tries with wrong username or a service account without sudo access.

Leave a Reply

Your email address will not be published. Required fields are marked *