Linux systems rely on secure credential management, and knowing how to change the password of a user in Linux is a fundamental skill for administrators and power users. The process varies depending on whether you’re modifying your own account, another user’s credentials, or working across remote servers. Unlike proprietary systems, Linux offers granular control through command-line tools, but missteps can lock users out or expose vulnerabilities. Whether you’re troubleshooting an expired password, enforcing security policies, or simply maintaining system hygiene, understanding these methods is non-negotiable. The stakes are higher in enterprise environments where misconfigured passwords can lead to compliance violations or breaches. Even in personal setups, weak credentials risk unauthorized access to sensitive data. Linux’s flexibility means solutions range from basic `passwd` commands to advanced scripts integrating with LDAP or Active Directory. The challenge lies in balancing usability with security—especially when dealing with sudo privileges or system accounts. For those new to Linux, the terminology alone can be daunting: shadow passwords, PAM modules, and cryptographic hashes all play roles in the process. Yet the core mechanics are straightforward once broken down. This guide cuts through the noise to deliver actionable steps, from local terminal adjustments to remote server modifications, while addressing common pitfalls and security considerations. how to change the password of user in linux

The Complete Overview of how to change the password of user in Linux

Linux’s approach to password management reflects its design philosophy: transparency paired with security. Unlike GUI-driven operating systems, Linux handles credentials through command-line utilities that integrate with system authentication frameworks. The `passwd` command, for instance, serves as the gateway for most password changes, but its behavior shifts depending on user permissions and system configurations. For administrators, this means understanding not just the syntax but also the underlying mechanisms—such as how passwords are stored (typically in `/etc/shadow`) and validated (via PAM modules). The process isn’t one-size-fits-all. Changing your own password differs from modifying another user’s credentials, and remote server adjustments require additional steps like SSH authentication. Even the method for system accounts (e.g., `root`) or service-specific users (e.g., `mysql`) varies. What unifies these scenarios is the principle of least privilege: ensuring users only modify passwords they’re authorized to access. This guide covers the spectrum, from basic commands to advanced troubleshooting, while emphasizing security best practices to prevent brute-force attacks or credential leaks.

Historical Background and Evolution

Early Unix systems stored passwords in plaintext within `/etc/passwd`, a security flaw that led to the creation of the `/etc/shadow` file in the 1980s. This file, accessible only to root, encrypted passwords using algorithms like DES, later replaced by stronger hashing methods like SHA-256 and SHA-512. The `passwd` command, introduced in Unix Version 7 (1979), evolved to interact with these files, while Pluggable Authentication Modules (PAM) added flexibility for multi-factor authentication and policy enforcement. Linux inherited and expanded these foundations. Distributions like Debian and Red Hat integrated PAM with tools like `chpasswd` and `usermod`, enabling bulk password changes and scripted automation. Modern systems also support passwordless authentication via SSH keys, but traditional password management remains critical for compatibility and legacy systems. Understanding this history contextualizes why commands like `passwd -l` (lock) or `passwd -u` (unlock) exist—they’re remnants of Unix’s security-first mindset.

Core Mechanisms: How It Works

At its core, changing a user’s password in Linux involves three steps: verifying permissions, updating the credential store, and enforcing policies. The `passwd` command handles the first two by default, while PAM modules (configured in `/etc/pam.d/`) govern the third. For example, when you run `passwd username`, the system checks: 1. **Authentication**: Is the requester authorized (e.g., root or the target user)? 2. **Storage**: Does the password meet complexity rules (e.g., length, special characters)? 3. **Propagation**: Should the change apply to other services (e.g., sudo, SSH)? Passwords are stored as hashes in `/etc/shadow`, not plaintext, with fields for expiration dates and failed login attempts. The `crypt(3)` library handles hashing, and modern Linux distros default to SHA-512. This design prevents offline attacks while allowing administrators to audit credentials via tools like `shadow-utils`.

Key Benefits and Crucial Impact

Knowing how to change the password of user in Linux isn’t just about fixing a forgotten credential—it’s about maintaining system integrity. For administrators, this skill reduces downtime from locked accounts or policy violations. For security teams, it enables proactive measures like enforcing password rotation or disabling weak credentials. Even in personal use, it prevents unauthorized access to shared systems. The impact extends beyond technical efficiency. Proper password management aligns with compliance standards (e.g., PCI DSS, HIPAA) by ensuring credentials meet complexity and expiration requirements. It also mitigates risks like credential stuffing, where attackers exploit reused passwords across systems. By mastering these techniques, users gain control over their digital environment—whether managing a home server or overseeing an enterprise infrastructure.
*"Security is not a product, but a process. Password management is the first line of defense in that process."* — **Linux Foundation Security Best Practices Guide**

Major Advantages

  • Granular Control: Linux allows per-user password policies (e.g., expiration dates, lockout thresholds) via PAM configurations.
  • Scripting and Automation: Tools like `chpasswd` enable bulk password changes for large user bases, reducing manual errors.
  • Integration with Authentication Systems: Supports LDAP, Active Directory, and Kerberos for centralized credential management.
  • Audit Trails: Changes to `/etc/shadow` can be logged via `auditd`, providing accountability.
  • Flexibility for Edge Cases: Special handling for system users (e.g., `root`) or service accounts (e.g., `postgres`).
how to change the password of user in linux - Ilustrasi 2

Comparative Analysis

Method Use Case
passwd username Changing another user’s password (requires sudo).
sudo passwd -l username Locking a user account (e.g., after suspicious activity).
chpasswd < username:newpassword > Bulk password changes via scripts (common in enterprise).
usermod --password < hash > username Setting a password via hashed value (useful for automation).

Future Trends and Innovations

The future of Linux password management leans toward zero-trust models and biometric integration. Tools like `sudo` are evolving to support hardware-backed authentication (e.g., YubiKey), while distros like Ubuntu are phasing out traditional passwords for root access in favor of SSH keys. Additionally, AI-driven password managers (e.g., Bitwarden CLI) are gaining traction, though they introduce new dependencies. For enterprises, Single Sign-On (SSO) via OAuth2 and OpenID Connect will further reduce password sprawl. On the security front, quantum-resistant algorithms (e.g., NIST’s CRYSTALS-Kyber) may replace SHA-512, though adoption is years away. Meanwhile, Linux’s open-source nature ensures these innovations will be community-driven, with tools like `pass` (Unix password store) setting the standard for transparency. how to change the password of user in linux - Ilustrasi 3

Conclusion

Mastering how to change the password of user in Linux is more than memorizing commands—it’s about understanding the ecosystem that governs access. Whether you’re a sysadmin enforcing policies or a developer securing a CI/CD pipeline, these techniques form the bedrock of system hygiene. The key is balancing convenience with security: enforcing strong passwords without sacrificing usability. As Linux continues to dominate servers, desktops, and cloud infrastructure, the skills outlined here will remain relevant. The shift toward passwordless systems doesn’t diminish their importance; instead, it underscores the need for hybrid approaches. For now, the `passwd` command remains the Swiss Army knife of Linux authentication—versatile, powerful, and indispensable.

Comprehensive FAQs

Q: Can I change another user’s password without knowing their current one?

A: Yes, as root or via `sudo`, you can bypass the current password requirement. For example, `sudo passwd username` prompts only for the new password. However, this should be used cautiously to avoid unauthorized access.

Q: What if I forget the root password?

A: Boot into single-user mode (hold Shift during startup, select "Recovery Mode"), remount the filesystem as read-write, and use `passwd root` to reset it. This requires physical or console access.

Q: How do I enforce password complexity rules?

A: Edit `/etc/pam.d/common-password` and adjust settings like `pam_cracklib.so` for minimum length or `pam_unix.so` for retry limits. Example: `password required pam_cracklib.so minlength=12`.

Q: Why does `passwd` fail with "Authentication token manipulation error"?

A: This typically occurs when PAM modules are misconfigured or the user’s shell is corrupted. Check `/etc/pam.d/system-auth` and verify the user’s shell in `/etc/passwd` (e.g., `/bin/bash`).

Q: Can I change a password remotely via SSH?

A: Yes, but you must first authenticate as the target user or root. Use `ssh user@host "passwd"` or `sudo -u username passwd` after gaining access. Ensure SSH keys are set up to avoid password prompts.

Q: How do I set an expiration date for a password?

A: Use `chage -M days username` (e.g., `chage -M 90 alice` to expire in 90 days). Check current settings with `chage -l username`. This modifies `/etc/shadow` directly.

Q: What’s the difference between `passwd` and `chpasswd`?

A: `passwd` is interactive and requires TTY input, while `chpasswd` reads from stdin (e.g., `echo "username:newpass" | chpasswd`). The latter is ideal for scripts but less secure if misused (e.g., plaintext passwords in logs).

Q: How do I audit password changes?

A: Enable auditing with `auditctl -a exit,always -F path=/etc/shadow -F perm=cw`. Logs appear in `/var/log/audit/audit.log`. For real-time monitoring, use `ausearch -f /etc/shadow`.

Q: Can I change a password for a non-login user (e.g., `www-data`)?

A: Yes, but the process is identical to regular users. However, non-login users often rely on service-specific credentials (e.g., database passwords), so verify the context first.

Q: What’s the safest way to store password hashes?

A: Use `/etc/shadow` for system users and avoid storing plaintext hashes. For applications, use dedicated tools like `htpasswd` (Apache) or `openssl passwd`. Never commit hashes to version control.