πŸ‘₯ Linux/Unix: User, Group & Security Management
Estimated reading: 4 minutes 23 views

πŸ” Linux/Unix: Authentication Tools – passwd, su, sudo, /etc/sudoers Explained

🧲 Introduction – Why Learn Linux Authentication Tools?

Authentication is the first line of defense in Linux security. Whether it’s setting user passwords, switching identities, or granting privilege escalation, tools like passwd, su, sudo, and /etc/sudoers form the foundation of secure user management.

🎯 In this guide, you’ll learn:

  • How to set and manage passwords
  • How to switch user identities
  • How to configure and use sudo for secure privilege elevation
  • How to edit and safely manage the /etc/sudoers file

πŸ”‘ 1. passwd – Change User Passwords

βœ… What is passwd?

The passwd command allows users and admins to change user account passwords and set password aging policies.

πŸ› οΈ Syntax:

passwd [username]

πŸ§ͺ Example 1: Change your own password

passwd

πŸ“€ Output:

Changing password for user bob.
Current password:
New password:
Retype new password:

πŸ§ͺ Example 2: Change another user’s password (as root)

sudo passwd alice

πŸ‘€ 2. su – Switch User Identity

βœ… What is su?

su stands for substitute user. It lets you switch to another user account (including root) by authenticating with their password.

πŸ› οΈ Syntax:

su [username]

πŸ§ͺ Example 1: Switch to root user

su -

πŸ“€ Output:
Prompts for the root password. The - starts a full login shell.

🧠 Requires root password. Not preferred for shared access environments.


βš™οΈ 3. sudo – Run Commands as Another User

βœ… What is sudo?

sudo lets permitted users run commands as root or another user, without knowing their password, using rules defined in /etc/sudoers.

πŸ› οΈ Syntax:

sudo command

πŸ§ͺ Example 1: Run a privileged command

sudo apt update

πŸ“€ Output:
Prompts for your user password (not root’s) and executes the command as root.


πŸ” Sudo Features:

  • Logs all commands (auditability)
  • Enforces role-based access
  • Can restrict or allow specific commands

🧠 After entering your password once, sudo grants a 5-minute grace period by default.


πŸ“ 4. /etc/sudoers – Sudo Permissions File

βœ… What is /etc/sudoers?

It defines which users can run which commands as root. Must be edited carefully using visudo to avoid syntax errors that can lock out all users.

πŸ” Open with:

sudo visudo

πŸ§ͺ Common Syntax:

username ALL=(ALL) ALL

πŸ”Ή Grant john root privileges:

john ALL=(ALL:ALL) ALL

πŸ”Ή Allow deploy to restart nginx only:

deploy ALL=NOPASSWD: /bin/systemctl restart nginx

πŸ”Ή Group-based Access:

%sudo   ALL=(ALL:ALL) ALL

βœ… Anyone in the sudo group has root privileges via sudo.


πŸ” Tool Comparison Table

Command/FilePurposeRequires PasswordRole-Based AccessLogging Support
passwdChange passwordsβœ… Yes❌ No❌ No
suSwitch users (usually root)βœ… Yes (target’s pw)❌ No❌ No
sudoRun commands as another userβœ… Yes (your pw)βœ… Yesβœ… Yes
/etc/sudoersConfigure sudo permissions❌ Not a commandβœ… Yesβœ… Yes (via sudo)

πŸ“Œ Summary – Recap & Next Steps

Authentication tools like passwd, su, and sudo are vital for secure access control in Linux. Properly managing /etc/sudoers ensures that only authorized users can perform sensitive operations without compromising system integrity.

πŸ” Key Takeaways:

  • Use passwd to manage user authentication securely.
  • Prefer sudo over su for better control and auditing.
  • Use visudo to safely edit /etc/sudoers.
  • Grant fine-grained privileges without exposing root passwords.

❓ FAQs

❓ What’s the difference between su and sudo?
βœ… su requires the target user’s password. sudo uses your own password to run commands as root or another user based on /etc/sudoers.

❓ How can I give a user sudo access?
βœ… Add the user to the sudo group:

sudo usermod -aG sudo username

❓ Why should I use visudo instead of editing /etc/sudoers directly?
βœ… visudo checks for syntax errors and prevents file corruption that could lock you out.

❓ Can I limit what commands a sudo user can run?
βœ… Yes. In /etc/sudoers, assign specific commands:

bob ALL=NOPASSWD: /usr/bin/systemctl restart apache2

❓ Where are sudo logs stored?
βœ… Typically in:

/var/log/auth.log     # Debian/Ubuntu
/var/log/secure       # RHEL/CentOS

Share Now :

Leave a Reply

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

Share

πŸ”΅ Linux/Unix: Authentication (passwd, su, sudo, /etc/sudoers)

Or Copy Link

CONTENTS
Scroll to Top