Report this

What is the reason for this report?

Resetting and accessing Droplet password

Posted on December 1, 2014

If I reset my password will this update the passwd file?

The reason that I ask is because I foolishly edited my /etc/passwd manually and in the process deleted the root user line. Now I am unable to use sudo to edit the file.

My solution is to purchase a new droplet and replicate my existing server. However I am not sure if this is truly necessary. I am fairly new to server admin, hence the foolish behaviour of manually editing my passwd file! Any info would be greatly appreciated.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

No, resetting the password updated /etc/shadow where the password is actually stored.

Follow Attempt Recovery with a Recovery ISO | How To Recover from File System Corruption Using Fsck and a Recovery ISO | DigitalOcean. You can skip the Set Up Networking in the Recovery Environment section.

Once you’ve mounted the filesystem, open /mnt/etc/passwd in nano or any other editor, and add the following line at the beginning:

root:x:0:0:root:/root:/bin/bash

Then, save the file, unmount the filesystem, and power off the droplet:

cd /
umount /mnt
poweroff

Finally, reply to the support ticket to remove the ISO image from the droplet so you can then boot your droplet normally.

Hi, Just want to say a big thank you for your help on this issue. Finally, after a month I got round to fixing this.

Yes, resetting your root password can potentially help, but it won’t directly restore the missing entry in /etc/passwd. When you change the password using a reset tool it typically updates the password hash in /etc/shadow, but it does not restore the /etc/passwd file, which contains essential account information like user IDs.

Since you’ve deleted the root user entry, your system won’t recognize the root user for logins or any root-level operations like sudo.

You can boot into a recovery or rescue mode where you’ll have access to the filesystem without needing root or sudo permissions. Here’s what you can do:

  1. Boot into recovery or rescue mode from your provider’s dashboard.
  2. Mount the disk (usually under /mnt or /media).
  3. Navigate to the mounted filesystem and manually edit the /etc/passwd file to restore the root user line.
  4. Add this line (or something similar, depending on your distro) to restore the root user:

root:x:0:0:root:/root:/bin/bash

Then save the file and reboot back into normal mode.

If you have any backups or snapshots of the system, you can restore the /etc/passwd file from there.

If you’re completely locked out and cannot get into recovery mode, you could spin up a new droplet and replicate the setup from your current system. You can still mount the old droplet’s filesystem in recovery mode and copy important data to the new droplet.

Regards

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.