How to Reset Password in Linux

How to Reset Password in Linux

How to Reset Password in Linux

(How to Reset Password in Linux) User and system administrator both need the crucial capability to reset passwords when using Linux operating systems. Linux contains multiple options for both password reset and user password modification. This guide explains various methods and circumstances for password resets in Linux systems.

Reset Password for a Regular User

Using the passwd Command

If you remember your password and want to change it, use the passwd command:

Using the passwd Command

You will be prompted to enter your current password, followed by the new password.

If you’re the root user and want to reset another user’s password, use:

If you're the root user and want to reset another user’s password, use:

Example:

Example:

You’ll be asked to enter the new password for the specified user.

Reset Password Using Recovery Mode (Single User Mode)

If you’ve forgotten your root password and can’t log in, follow these steps:

Step 1: Boot into Recovery Mode

  • Restart your system.
  • While booting, hold Shift (for GRUB menu) or press Esc (for UEFI systems).
  • Select the kernel with (recovery mode).
  • Choose Drop to root shell prompt.

Step 2: Remount Root Filesystem

By default, the filesystem is read-only. Remount it with write permissions:

Remount Root Filesystem

Step 3: Reset the Password

Run the following command:

Reset the Password

For example, to reset the root password:

For example, to reset the root password:

Enter the new password and confirm it.

Step 4: Reboot the System

Reboot the System

Now you can log in with the new password.

Reset Password via Live CD or USB

If you can’t access recovery mode, use a bootable USB:

Step 1: Boot from a Live CD/USB

  • Insert the bootable Linux USB.
  • Select Try Ubuntu (or similar option for other distros).
  • Open a terminal.

Step 2: Identify the Root Partition

Run:

Run:

Find the partition where Linux is installed (e.g., /dev/sda2).

Step 3: Mount the Partition

Mount the Partition

Step 4: Change Root Directory

Change Root Directory

Now reset the password:

Now reset the password:

Once done, unmount and reboot:

Once done, unmount and reboot:

Reset Password Using init=/bin/bash Method

This method is useful when GRUB is accessible but root access is lost.

Step 1: Edit GRUB

  • Restart your system.
  • Press e at the GRUB menu.
  • Locate the line starting with linux.
  • Append init=/bin/bash at the end.

Step 2: Boot into Bash Shell

Press Ctrl + X to boot. You’ll land in a root shell.

Step 3: Remount Root Partition

 Remount Root Partition

Step 4: Change Password

Change Password

After resetting the password, reboot:

After resetting the password, reboot:

Reset Password Using SSH (If Remote Access is Enabled)

If the system allows remote login, you can reset the password using SSH.

Connect to the system:

Connect to the system:

Run the password reset command:

Run the password reset command:

Logout:

Logout:

Alternative Commands for Password Management

chage – Manage Password Expiry

Check password expiration:

Check password expiration:

Set password to expire in 30 days:

Set password to expire in 30 days:

Force password change on next login:

Force password change on next login:

usermod – Lock/Unlock User Account

Lock a user account:

Lock a user account:

Unlock a user account:

Unlock a user account:

passwd with Expiry Options

Expire a password immediately:

Expire a password immediately:

Set a password that never expires:

Set a password that never expires:

Conclusion

A simple process exists for resetting passwords in Linux systems when recovery options are available. Users have at least one method among passwd, GRUB modifications, Live USBs, and SSH to recover access to their system. Strong passwords together with multi-factor authentication should be enabled because they boost security measures.

Additional Tips

  • Regularly backup critical data.
  • Keep a recovery USB handy.
  • Use a password manager to avoid forgetting passwords.
  • Implement account lockout policies to prevent unauthorized access.
  • Keep your system updated to patch security vulnerabilities.
  • Consider using SSH keys instead of passwords for remote access.
  • Enable disk encryption for an additional layer of security.
  • Familiarize yourself with Linux recovery tools to prepare for emergencies.
  • Set up email or phone recovery options if your Linux distribution supports them.
  • Educate users on best practices for password security.
  • Use fail2ban or similar tools to prevent brute-force attacks.
  • Change default passwords immediately upon setting up new user accounts.
  • Regularly audit user accounts and remove inactive ones to maintain security.

By following these methods, you can efficiently manage user accounts and recover access whenever necessary.

Leave a Reply

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