Change Linux Password

This guide explains how to change a user’s password on Linux, both in a normal environment and in recovery mode.


Changing Password in Normal Mode

  1. Open Terminal:

    • For desktop systems, open the terminal via the application menu.
    • For servers, log in via SSH or the local console.
  2. Set the Password: Enter the following command:

    passwd
    
    • You will be prompted to enter your current password.
    • Then, you can set a new password.
  3. Confirmation: If the change is successful, a confirmation message will appear.


Changing Password in Recovery Mode

If the normal password is forgotten, it can be changed through recovery mode:

Step 1: Access GRUB Boot Menu

  1. Restart the system.
  2. During the boot process, hold the Shift key (for BIOS systems) or Esc key (for UEFI systems) to open the GRUB menu.

Step 2: Edit Boot Line

  1. Select the entry for your operating system and press e to edit the boot options.
  2. Locate the line starting with linux, for example:
    linux /boot/vmlinuz-... root=UUID=... ro quiet
    
  3. Replace ro quiet with:
    rw init=/bin/bash
    

Step 3: Boot into Root Shell

  1. Press Ctrl + X or F10 to boot with the modified settings.
  2. You will be taken directly to a root shell.

Step 4: Change the Password

  1. Set a new password for the root user:
    passwd root
    
  2. If another user account is affected, reset its password:
    passwd <username>
    

Step 5: Save Changes and Restart

  1. Sync the filesystem changes:
    sync
    
  2. Restart the system:
    reboot -f
    

Tips and Notes

  • Choose a strong password with a combination of uppercase and lowercase letters, numbers, and special characters.
  • For server systems, consider using SSH keys as an alternative to passwords.

Note: This guide works for most Linux distributions (Debian, Ubuntu, CentOS, Fedora, etc.). Variations may occur depending on specific configurations.

+++