How Recover or Rest lost ROOT password on centos dedicated server

totallyfreak

Verified User
Joined
Mar 13, 2013
Messages
25
Hi, i know there is many post like this one on this forum but all dont work for me...

im running on CentOS 6.5 on OVH dedicated server

i format my pc and where my root password was save... the hard drive crash and get corrupted so i dont remember my root password
i know my directadmin ADMIN password but not the ROOT password to make some server change via SSHexplorer

the solution i found was to reboot the server in rescue mode
after

fdisk -l
the root one is marked with an asterisk. Thus now you can use the following command to mount the root partition:



the problem is that the 2 partition that i see after this command dont have an asterisk
root@rescue:~# fdisk -l

WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sda1 1 3907029167 1953514583+ ee GPT
Partition 1 does not start on physical sector boundary.

WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sdb1 1 3907029167 1953514583+ ee GPT
Partition 1 does not start on physical sector boundary.

Disk /dev/md2: 1996.2 GB, 1996200280064 bytes
2 heads, 4 sectors/track, 487353584 cylinders, total 3898828672 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

Disk /dev/md2 doesn't contain a valid partition table


so what can i do or wich partition should i use?
 
Hello,

try this

Code:
mkdir -p /mnt/sda1
mount /dev/sda1 /mnt/sda1

in rescue mode and then browse /mnt/sda1. And update root password.

Please feel free to PM me if you need someone to fix it for you.
 
It depends. If you don't mount the partition and don't chroot to it, then you should update the file password file manually in an editor.
 
Let's be more specific:

In the mounted drive's filesystem find and cd to etc/. This is not the same as /etc, which is the /etc directory of the recovery system's drive.

Immediately make a copy of the shadow file because if you screw up the next few steps you'll need to copy it back or you won't be able to login as anyone.

Then in this shadow file find the line which begins root.

In that line, remove the data between the first : character and the second : character. then you should be able to login as root the way you normally do but without a password.

Immediately do so and use the passwd command as root to reset the password. Do this right away as anyone can log in as root without a password until you do.

I'm not positive this will work because your distribution may block root if it doesn't have a password. Try it.

Jeff
 
By default OpenSSH does not allow empty passwords. So your method requires more modifications.

Provelink: http://www.openssh.com/cgi-bin/man.cgi?query=sshd_config

PermitEmptyPasswords
When password authentication is allowed, it specifies whether the
server allows login to accounts with empty password strings. The default is ``no''.

It's easier to create a new password hash with openssl:

Code:
[COLOR=#666666]openssl passwd -1 MySecretNewPass[/COLOR]


example:

Code:
# openssl passwd -1 MySecretNewPass
$1$F82vi5is$RDA1KkgBUTvAVRDaWyVVR1

Change
MySecretNewPass with your password and add hash ($1$F82vi5is$RDA1KkgBUTvAVRDaWyVVR1) to a shadow file so it would look like:

Code:
[root@server]# cat etc/shadow | grep root
root:$1$F82vi5is$RDA1KkgBUTvAVRDaWyVVR1:15565:0:99999:7:::
[root@server]#
 
ok now im lost

So in the final... what i really need to do with ssh explorer or putty
step by step please... im really not good with server config and management.. im mostly a web designer


thx
 
That all was already posted here, follow the steps

1. mount partition (see post #3 here)
2. find the file (see post #6 here)
3. update password (see post #7 here)
 
Thanks, zEitEr, for the correction; I wasn't sure.

One way aro9und it is, after rebooting in Rescue Mode, reboot in single-user mode. Then you should be able to log in as root without Password and change it there.

However, I'm not sure any of this is helpful to poster if he cannot login remotely:
So in the final... what i really need to do with ssh explorer or putty
For your solution you must login in Rescue Mode (and with my idea later in Single User Mode) through either KVM or IPMIl, and not with Putty.

Or am I missing something?

Jeff
 
To replace root's password in shadow file should be enough. If you don't want to mess the file then you probably could give permissions to another user to use 'sudo'. Or add the second superuser.
 
Back
Top