0

I had an accident with /etc/passwd - using putpwent(), I replaced the first line of /etc/passwd with mine.
Unfortunately this line used to belong to root.
Now I don't have root permission, and I can't change it back.
The file belongs to user 0 group root:
-rw-r--r-- 1 0 root 1.8K Jan 9 11:33 passwd

Any idea how to recover?

4 Answers 4

3

When the bootloader shows up, add

init=/bin/bash 

instead of booting normally edit kernel parameters, so for different distro you can find your solution but it should be according to your needs :

mount -o remount,rw /dev/sda1 

and change your root credentials and then it should be ok

4
  • Well I didn't think to this one that can also work Commented Jan 9, 2014 at 10:29
  • Since I don't have root user, I'm afraid I'll not be able to start a single user session. what do you think? Commented Jan 9, 2014 at 10:31
  • 1
    at least you can try, from my point of view root user must be initiated with init=bin/bash Commented Jan 9, 2014 at 10:34
  • @RanRegev The bootloader is before loading kernel and going into multi or single user session. Commented Jan 9, 2014 at 11:11
2

What should work on most systems:

  • Download a live linux distro
  • Boot on the live linux
  • Mount your partition where the file is
  • Authenticate as root on the live linux
  • Use chroot to change your root to your partition
  • Edit your file with any editor: vi, nano, ed ?

Edit 1:

  • Or you can also consider to use passwd to change root password in your new root
2
  • @Zelda why any form of sympathy like good luck or It is a pleasure is remove every time someone use them ? what's the problem with being polite ? Commented Jan 9, 2014 at 11:12
  • 3
    You write it only once but you force others to many times waste their precious time to read through non-essential parts of an answer (or question). Better answer and question have no "thank you", "good luck", "I would like to know what ..." instead "What ...", etc. Keep it Answers and Questions crisp, that makes them better. Commented Jan 9, 2014 at 12:04
1

You can boot using any LiveCD Linux like Ubuntu, SystemRescueCD ..etc Then locate your partition containing /etc :

# Using root user of the LiveCD session. fdisk -l 

This will show you all partitions. Now mount them one by one

mkdir /mypartition mount /dev/sd<x> /mypartition 

Until you locate the partition with your /etc.

Now you can edit your passwd file to recover it to the right version.

0
0

If you have another account on the machine and still can do sudo in there (i.e. sudo asks for the accounts password and not root password). You can use that to get root permissions and change /etc/passwd.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.