Re: Lose Linux root password



On June 9, 2009 13:00, in alt.os.linux, Ivan Marsh (ivanmarsh@xxxxxxxxx)
wrote:

Johnson wrote:

I lose my root password, and couldn't get into the Linux. I have some
data stored in the hard drive, and I don't want to lose them. What is
the easiest way to recover the system?

Thanks.

Assuming you're using grub as the boot loader, edit the kernel parameters
at boot and add "single" to the end of the line that loads the kernel.

Then run passwd from the maintenance prompt and change the password.

"Single user" mode, initiated from grub or from lilo kernel parameter list,
will not guarantee unfettered root access to a standard Linux-based system.
Most distributions protect even the single-user mode with a password-based
login prompt. Thus, despite the Linux Gazette advice (as pointed out by
another poster) and the advice of Mr. Marsh, above, "single" won't
necessarily permit the OP to fix his problem.

If it works, then it works. But, if it doesn't, then the OP can use a "live
distro" to recover his files.

To the OP: If "single user" mode doesn't let you in, then
- boot a "live distro" CD, like Ubuntu
- obtain a commandline (run xterm or terminal or something)
- get root; with "live boot" distros, this is usually dead simple, as the
root password is usually provided as part of the documentation
- mount your real root directory onto an unused directory of the live boot
environment (i.e. onto /mnt). Make certain you mount it rw
- cd to your newly-mounted root directory
- enter the following command: "chroot . /bin/bash" to obtain a command
prompt that uses your newly-mounted root directory and /it's/ files
(including it's etc/passwd and etc/shadow)
- enter the passwd command to change roots password
When you are done
- enter "exit" to quit the chroot shell
- cd to the real /
- umount your installation's root directory
- shutdown and reboot

What this does is permit the password program from /your/ installation to
work on the password files from /your/ installation, by running everything
in an environment that starts with your installation as the root
filesystem. Up to the point where you chroot, you are just establishing a
running environment, but when you chroot, you have effectively
re-established /your/ installation, with access as root.

Hope this helps
--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------


.



Relevant Pages

  • Re: grub error 18
    ... Do you boot some of your installed OSes from sdb? ... # linux installation on /dev/sdb2. ... root ...
    (uk.comp.homebuilt)
  • Re: Help 10.3 a mess After YOU Upgrade
    ... It points to boot partition where GRUB can find it's files. ... purpose it will point to installation that is used to store GRUB files ... root # This new added. ...
    (alt.os.linux.suse)
  • Re: How to login on a SUN machine without any account, any password?
    ... > I was asked to install three sun servers yesterday. ... You use the root password. ... If you ran the installation procedure, ... will have to boot from the installation media in single-user mode ...
    (comp.unix.admin)
  • Re: RO4 and the pinboard - a quick question
    ... the root directory of the hard drive arrived in its ... window in the middle of the screen automatically. ... clicking on the 'Boot' piece, ...
    (comp.sys.acorn.hardware)
  • [Fwd: [opensuse] OpenSUSE 11.1 Boot Loader Problem]
    ... After sendint the forwarede message I stumblen on a way to boot to my configured the way I like it OpenSUSE 10.3 installation. ... I installed 111.1 on a new 500GB SATA HD without any complaints or problems, until I rebooted the system without the installation DVD in it's drive. ... root ...
    (SuSE)