Password recovery & hostname changes in linux recently happened to me when I while messing with my system, i wrote a script to change root password & set it to expire in every 7 days & simultaneously making changes to hostname by setting it to a random value.. I queried my friend Raghu for inputs regarding it & got some interesting results,which I will be compiling here. This tutorial is intended for Linux newbies & would help them to get familiar with the enviornment. Actually, after 7 days what happened I tried to log in,& it always said "root password expired, please contact your administrator"..seems familiar ? is how you can eradicate this.

( PS:
Folks..if you think you are too dumb to do
that, there exists an automated "burn-the-cd-boot-&-forget-solution"
called KONBOOT which can reset Linux passwords if you care.. :D choose your pick

I actually rebooted the system & once I reached grub,selected the kernel, I pressed "e".I proceeded to 2nd line of configuration & pressed "e" again.

kernel /boot/vmlinuz- ro
Obviously, I edited the file by pressing "e" again & modifying it by typing "single" for invoking single user mode in Linux.
kernel /boot/vmlinuz- ro single
Press "b" key to boot. Afterwards, you are given a prompt, please enter "passwd" command to reset root password.
After that, login as root & then proceed to move to /etc/shadow

[root@zion XERO]# cd /etc
[root@zion etc]# vi shadow
& check the entry for root,it should look similar to this


you can see there is a "1" in last entry which sets the root account to expire. remove it such that it becomes


Once done, save the file & exit by pressing :wq! in vi. After that, boot into graphical mode by typing

[root@zion XERO]# init 5
login with your password."root" problem solved :) After wards..i found out that my hostname was, here are three easy ways to change your hostname on your will.

Way 1
open console, & type
[root@zion XERO]# hostname
now you can reset hostname (for the given session) by typing -
[root@zion XERO]# hostname
where is your new hostname.

The second way deals with editing a file known as "network" located in /etc/sysconfig/network, navigate to it

[root@zion XERO]# cd /etc/sysconfig/
check the value of hostname in it
[root@zion sysconfig]# cat network
time to change it, go to vi & edit it.
[root@zion sysconfig]# vi network
saved the file..reboot & its done :)

The third way deals with "sysctl" command, which can be used to change the variable kernel.hostname. Start by checking its current value by typing

[root@station3 sysconfig]# sysctl kernel.hostname
kernel.hostname =
and to change it, enter

[root@station3 sysconfig]# sysctl kernel.hostname=MYHOST.TESTSITE.COM

where MYHOST.TESTSITE.COM is your new hostname.
All of this was scripted,tested in FEDORA 13 ( & written using Scrib Fire

I hope it was interesting :)

Like This post ?  You can buy me a Beer :)


Need to say something ? Spell it out :)