Ora

How do I reset my photon root password?

Published in Photon OS Password Reset 5 mins read

Resetting your Photon OS root password is a critical administrative task, especially if you've forgotten it or need to change it for security reasons. The process involves using the passwd command, but the approach differs depending on whether you can currently log in as root or have sudo access.

Two Ways to Reset or Change Your Photon OS Root Password

Whether you've forgotten your root password entirely or simply wish to update it, Photon OS provides clear methods to achieve this.

Method 1: Changing the Root Password (If You Know It)

If you are currently logged in as the root user or have a user account with sudo privileges, changing the root password is a straightforward process. This is the most direct way to update your password if you already have the necessary authentication.

Steps to Change Your Root Password:

  1. Open a Terminal: Access your Photon OS instance via SSH or directly through the console.
  2. Execute the passwd command: At the command prompt, type passwd.
  3. Enter New Password: You will be prompted to enter a new password for the root user.
  4. Re-enter New Password: Re-enter the new password to confirm it.

Example:

root@photon-os [ ~ ]# passwd
New password:
Retype new password:
passwd: password updated successfully
root@photon-os [ ~ ]#

Important Note: Ensure your new password conforms to the password complexity rules of Photon OS. These rules typically require a combination of uppercase and lowercase letters, numbers, and special characters, and a minimum length to ensure strong security. Always remember your new password for future access.

Method 2: Resetting the Root Password (If You Forgot It)

If you have forgotten the root password and cannot log in, you will need to access the system's GRUB bootloader to enter single-user mode. This method bypasses the normal login process, allowing you to reset the password from a root shell.

Steps to Reset Your Forgotten Root Password:

  1. Reboot Photon OS: Restart your Photon OS virtual machine or physical server.
  2. Access GRUB Menu: As the system boots, watch for the GRUB bootloader screen. You may need to press a key (often e or a function key like Esc or Shift) to interrupt the boot process and enter the GRUB edit mode.
  3. Edit Boot Parameters:
    • Locate the line that begins with linux /boot/vmlinuz....
    • Navigate to the end of this line.
    • Change ro (read-only) to rw (read-write).
    • Append init=/bin/bash to the end of the line.
      • Before: ... ro quiet
      • After: ... rw init=/bin/bash
  4. Boot with Modified Parameters: Press Ctrl+X or F10 to boot the system with these modified parameters.
  5. Access Root Shell: The system will boot directly into a root shell without asking for a password.
  6. Mount Root Filesystem (if necessary): Although rw was specified in GRUB, sometimes the root filesystem might still be read-only. To be safe, remount it as read-write:
    mount -o remount,rw /
  7. Reset Password: At the command prompt, type passwd.
    • You will be prompted to type and re-enter a new root password.
    • Crucially, ensure this new password conforms to the password complexity rules of Photon OS for strong security. It's vital to remember this new password for future access.
      passwd
      New password:
      Retype new password:
      passwd: password updated successfully
  8. Sync Changes: Run the sync command to ensure all changes are written to disk.
    sync
  9. Reboot System: Reboot your system. It's recommended to use exec /sbin/init or a hard reboot from your hypervisor/physical machine, as the system is not in a normal state.
    reboot -f

    Alternatively, you can just use the power-off/reset option from your VM management console.

After the reboot, you should be able to log in with your newly set root password.

Understanding Password Complexity

Photon OS, like most secure operating systems, enforces password complexity rules to protect against unauthorized access. While specific rules can vary with configuration, common requirements include:

  • Minimum Length: Often 8 or more characters.
  • Character Mix: At least one uppercase letter, one lowercase letter, one number, and one special character (e.g., !, @, #, $).
  • Avoid Dictionary Words: Passwords should not be easily guessed words or common phrases.
  • No Personal Information: Avoid using names, birthdays, or other easily accessible personal data.

These guidelines ensure that your root password is robust and resistant to brute-force attacks.

Important Considerations

  • Physical/Console Access: Resetting a forgotten root password typically requires direct physical or console access to the system, as you need to interact with the GRUB bootloader.
  • Security Best Practices: Always use strong, unique passwords for your root account. Consider using a password manager to keep track of complex passwords securely.
  • Sudo Access: If you frequently perform administrative tasks, consider setting up a non-root user with sudo privileges. This allows you to perform privileged commands without always logging in as root, reducing the risk of accidental system damage.

For more detailed information on Photon OS administration and security, refer to the official VMware Photon OS documentation.