Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I deleted the /etc/passwd file and cannot login now. I don't know the root password and tried lots of passwords, but none of them worked.

How can I fix this?

share|improve this question

marked as duplicate by user68186, Eric Carvalho, Pilot6, A.B., karel Jun 22 '15 at 2:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Why did you do that??? – user25656 Jan 27 '14 at 13:19
The easiest solution should be just using your latest backup. – Keba Jan 27 '14 at 13:21
how I use backup – Eren Jan 27 '14 at 13:23
The given answer is incomplete, you'd better restore the file from backup instead of creating a new one. You can find a backup at /etc/passwd- or in /var/backups/. – Lekensteyn Jan 27 '14 at 13:38
+1 for @Lekensteyn 's comment. there's a passwd.bak file under /var/backups/ .. simply restore it. :) – AzkerM Jan 27 '14 at 13:46

Here are the steps to do this graphically:

  1. Boot to a live Ubuntu environment using an Ubuntu bootable media;

  2. Start Nautilus file manager and mount your Ubuntu partition (here in the snapshot, it's the 129 GB Filesystem); snap1

    (Hit Ctrl + L to see the partition's UUID.) snap2

  3. Start Nautilus with root privilege (Press Alt + F2 and type gksu nautilus and hit enter); snap3

  4. The Ubuntu partition should show up in the side bar with its UUID. Click to mount it, and go to the /etc directory; snap4

  5. In /etc directory, scroll down to find the file named passwd- and make a copy of this in the directory (press-hold Ctrl key, place your mouse pointer over the file, press-hold the left mouse-button, drag the mouse pointer, and then release the mouse button followed by Ctrl key to make a copy in the same directory; a file named passwd- (copy) will be created); snap5

  6. Select the copy file, right-click and select rename. Then rename the file to passwd; snap6

  7. After the file has been renamed to passwd right-click and select Properties from the context menu, and in the tab Permissions set the appropriate permissions, i.e. the Owner root should have Read and write permission while for the Group and Others set the access to Read-only and close the properties window; snap7

  8. Now reboot your system and you should be able to log in with your password.

You can do the same using terminal in a live environment.

The steps:

  1. Boot to live Ubuntu session;

  2. Open a terminal or a tty and type in the command:

    sudo fdisk -l

    (and note your Ubuntu partition's device name which will be in the form /dev/sdX.)

  3. Mount the device,

    sudo mount /dev/sdXY /mnt

    (repace sdXY with your target device.)

  4. cd to the target systems /etc directory:

    cd /mnt/etc
  5. Use the backup file to restore, and set the appropriate permissions:

    sudo cp passwd- passwd
    sudo chmod 644 passwd

    Or use the backup in /var/backups/passwd.bak:

    sudo install -m 644 /mnt/var/backups/passwd.bak /mnt/var/backups/passwd

    (as pointed out by Lekensteyn in his comments)

  6. Then reboot your computer:

    sudo reboot
share|improve this answer
thanks for pointing out.. I'll make the edit.. – precise Jan 27 '14 at 13:51
Even shorter: sudo install -m644 /etc/passwd- /etc/passwd. Check the timestamps with ls -ltr /etc/passwd- /var/backups/passwd.bak (the newest file is listed last). Compare two files with: sudo diff -u /etc/passwd- /var/backups/passwd.bak – Lekensteyn Jan 27 '14 at 14:36
@hash just for query what is the advantage to mount with UUID? – souravc Jan 27 '14 at 17:27
..I have just used nautilus to do the mount operations, no manual use of UUID was done there. yes, I could have omitted the "UUID part" but I didn't.. You may note UUID being used as the partition label in the nautilus window with elevated privileges... – precise Jan 27 '14 at 17:39

This question seems to already have the suitable answers, I will just expand on @Lekensteyn 's comment:

sudo cp /var/backups/passwd.bak /etc/passwd
sudo chmod 644 /etc/passwd
share|improve this answer

If you are can login just open terminal and try this :

sudo cp /etc/passwd- /etc/passwd

sudo chmod 644 /etc/passwd


Boot into recovery mode or from Ubuntu live Cd . Then, mount your old drive:

mkdir /olddrive
mount /dev/hda5 /olddrive
assuming that your old drive is on /dev/hda5.
then, cd to /olddrive/etc
echo "root::0:0:Superuser:/:/bin/bash" > passwd

then reboot. That will set no passwd for root.

Then, you can login, create all of your accounts over again, etc.

You may also use the back up which is called(i think) /etc/passwd-

Edit:(another method "I don't try that before bu i think it should work also")

  • Start GRUB on boot (press ESC while booting)
  • Press e over (recovery mode)
  • Press e over the line beginning with kernel
  • Press Space bar and enter "init=/bin/bash"
  • Press enter
  • Press b
  • At command prompt type: "cp /etc/passwd- /etc/passwd"
  • Reboot to GRUB again
  • Press e over (recovery mode)
  • Press e over the line beginning with kernel
  • Press Space bar and enter "init=/bin/bash"
  • Press enter
  • Press b
  • At command prompt type "mount -o remount,rw /"
  • Type "passwd YOURUSERNAMEHERE" (IF you don't know your username type "ls /home" (that is a Lower case L and lower case S) for a list of users)
  • Enter new password at prompt
  • Reboot to normal boot.


share|improve this answer
thank you very much I try – Eren Jan 27 '14 at 13:25
you are welcome – Maythux Jan 27 '14 at 13:26
Please add a reference if copying from elsewhere – Wilf Jan 27 '14 at 14:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.