LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   accidentally commented root user at /etc/passwd (https://www.linuxquestions.org/questions/linux-general-1/accidentally-commented-root-user-at-etc-passwd-557113/)

karen.pertierra 05-27-2007 10:23 PM

accidentally commented root user at /etc/passwd
 
Hello everyone,

I need help on this asap.

I accidentally commented the root user at /etc/passwd.

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

thus, I cannot su - using SSH. It gives me the error:

su: user root does not exist

Can anybody help me on this?

Thanks in advace.

Karen

jtshaw 05-27-2007 10:31 PM

Your going to want to boot your machine on a live cd like knoppix, mount the drive, and uncomment out the root user. Then reboot without the CD and you should be just fine.... If you need any more in depth instructions let me know.

karen.pertierra 05-27-2007 10:37 PM

Thanks so much for that very quick reply.

Im a total Linux newbie, and yes I need a more detailed procedure.

1. Where can I download knoppix?
2. When you say mount the drive, how will I do that?

Cheers!

jtshaw 05-27-2007 11:07 PM

You can get Knoppix here.

I believe it will automatically mount your HD's in the /mnt or /media directory when it boots... but if not let me know and I'll attempt to walk you through it...

karen.pertierra 05-27-2007 11:22 PM

Thanks for the download link.

If I do the mount, will if affect any settings or files in the server? Will I not lose any information? When I do df-h, here is what I get.

Filesystem Size Used Avail Use% Mounted on
/dev/hda1 4.9G 206M 4.4G 5% /
none 121M 0 121M 0% /dev/shm
/dev/hda6 7.9G 786M 6.8G 11% /home
/dev/hda3 9.7G 1.5G 7.8G 16% /usr
/dev/hda2 9.7G 5.3G 4.0G 58% /var

dawkcid 05-28-2007 06:16 AM

You don't need a live cd. Just:

Append 'init=/bin/sh' to the boot command line.
remount / rw (mount -o remount,rw /)
edit /etc/passwd
remount ro (mount -o remount,ro /)
exec /sbin/init to continue booting normally (you don't need to reboot).

jtshaw 05-28-2007 08:05 AM

Quote:

Originally Posted by dawkcid
You don't need a live cd. Just:

Append 'init=/bin/sh' to the boot command line.
remount / rw (mount -o remount,rw /)
edit /etc/passwd
remount ro (mount -o remount,ro /)
exec /sbin/init to continue booting normally (you don't need to reboot).

You know... that probably is easier...

You can probably also append 'single' to the kernel parameters on bootup and get in that way.

jtshaw 05-28-2007 08:07 AM

Quote:

Originally Posted by karen.pertierra
Thanks for the download link.

If I do the mount, will if affect any settings or files in the server? Will I not lose any information? When I do df-h, here is what I get.

Filesystem Size Used Avail Use% Mounted on
/dev/hda1 4.9G 206M 4.4G 5% /
none 121M 0 121M 0% /dev/shm
/dev/hda6 7.9G 786M 6.8G 11% /home
/dev/hda3 9.7G 1.5G 7.8G 16% /usr
/dev/hda2 9.7G 5.3G 4.0G 58% /var

You might want to consider the above two posts as alternatives... but no, you won't lose any information.

If you were to do have to do the mount yourself through knoppix open up a terminal and do the following

mkdir /mnt/hda1
sudo mount /dev/hda1 /mnt/hda1
edit /mnt/hda1/etc/passwd
reboot

karen.pertierra 05-29-2007 12:17 AM

Originally Posted by dawkcid
You don't need a live cd. Just:

Append 'init=/bin/sh' to the boot command line.
remount / rw (mount -o remount,rw /)
edit /etc/passwd
remount ro (mount -o remount,ro /)
exec /sbin/init to continue booting normally (you don't need to reboot).


Hi dawkcid,

Im using SSH. When I typed, init-/bin/sh, in the "Login as" prompt, it asked for a password. I typed the password for root, but did not accept it.

login as: init=/bin/sh
init=/bin/sh@202.91.163.28's password:
Access denied

Any ideas? Or I should type directly to the actual server's prompt and not thru SSH?

Thank for your help. :)

jschiwal 05-29-2007 12:29 AM

Do you have physical access to the computer?

The init=/bin/bash is a kernel boot option and not an ssh login name.

karen.pertierra 05-29-2007 01:14 AM

Yes, I also have physical access to the server.

Can you walk me through the process?

Sorry, Im a total linux newbie and not so familiar with that kernel boot thing.:scratch:

jschiwal 05-29-2007 08:28 AM

Enter init=/bin/bash in the boot menu's kernel options.

Then run an editor such as vim and edit out the comment character.

You can also use sed to delete the "#" character on the line containing root:
sed -i '/root/s/#root/root/' /etc/passwd

karen.pertierra 05-29-2007 10:53 PM

when i typed: init=/bin/sh to the boot command line, It says :

the kernel parameter does not exist.
Even when I use/type 'single', it gives the same kernel error.

Any ideas?

karen.pertierra 05-29-2007 11:01 PM

oh sorry about that, the error said:

Could not find kernel image: init=/bin/sh

or if i type 'single'

Could not find kernel image: single

Any ideas?

jschiwal 05-30-2007 01:14 AM

Add "init=/bin/bash" to the end of what is there. If that doesn't work or there isn't anything on the line try "linux init=/bin/bash".
The single option might work, but I think you may need the a root password, which won't work in your case.

Another option is to boot up with a rescue disk, mount the root partition and edit out the "#" character you added. Then save the file and reboot.


All times are GMT -5. The time now is 08:52 AM.