Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 463
  • Last Modified:

Linux changed /etc/passwd and can not login now

I changed the last part in /etc/passwd to
/root instead of /sbin/bash

and now I can not login using shell command

can anyone please please help. Its urgent


it was

root:*:100:100:8A-74(office):/:/root

changed it to

root:*:100:100:8A-74(office):/home/smith:/root
0
syedasimmeesaq
Asked:
syedasimmeesaq
  • 10
  • 2
2 Solutions
 
Maciej SsysadminCommented:
Can you login as some other user? If so, and if you have sudo installed, you may run: sudo vipw (or sudo vim /etc/passwd) and correct this. Use your preferred editor in case you don't know/like vim.

If you cannot login as normal user and/or you don't have sudo, you need to boot from some live cd, then mount your / partition, then edit and correct your /etc/passwd.
0
 
syedasimmeesaqAuthor Commented:
I think the shell account is messed up. Cause I am trying to use putty to login. Do you think the root will work on physical machine though?
0
 
syedasimmeesaqAuthor Commented:
I can not just reformat and use partition again as it is in production
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
syedasimmeesaqAuthor Commented:
correction:

it was

root : * : 100 : 100 : 8A-74(office) : / : /sbin/bash

changed it to

root : * : 100 : 100 : 8A-74(office) : / : /root
0
 
TintinCommented:
oklit, isn't suggesting a repartition.

If you have a non-root user on the system with sudo access, you'll be able to recover the situation easily.

If not, then you'll need to boot off a live CD as per oklit's suggestion.
0
 
syedasimmeesaqAuthor Commented:
well how do I do the live cd. Its centos system
now fortunately I think the root user is logged into the system at the location still. I am thinking to run there tomorrow and see if I can change the passwd file again to point it to right direction.
But wouldn't know till tomorrow
0
 
Maciej SsysadminCommented:
Ok, if you have some session logged still available then use it to correct your /etc/passwd :)
If you don't have this session, then download some live cd (or use your own if you have - maybe you still have centos installation cd? First one should be 'normal' livecd as far as I remember).
Remember that reboot is needed as you need to boot from such cd.
0
 
syedasimmeesaqAuthor Commented:
unfortunately session was logged out. so should i go to centos 5 site and  download the cd? the live cd.
and what to do after that. Live cd insert in the drive and then?????? Would it not reinstall the whole thing?
I am worried of loosing anything and not a linux expert so I just wanna make sure what happens after I put in the live cd. Thank you very much for all your help in this regard.

0
 
syedasimmeesaqAuthor Commented:
>>>>you need to boot from some live cd,
ok i downloaded the live cd.

>>>then mount your / partition,
how do i do that


>> then edit and correct your /etc/passwd.

how would i do this


thanks
0
 
syedasimmeesaqAuthor Commented:
I tried another system, (Not the production 1) and I damaged the etc/passwd file just the way it happened in the production server, then I put the centos 5.2 cd in the server. I tried to boot it. and it reinstalled everything...Now I am more paniced to use it in the real server than before!
Any help will be appreciated
thanks
0
 
syedasimmeesaqAuthor Commented:
ok I Followed these steps to reset the password using Gentoo live cd, but a problem is that its not finding my hard drive at /dev/hda0
it gives me an error
/dev/hda1 work but doesn't save anything

what could I be doing wrong



Reboot the system and configure it to boot from the Knoppix CD (instructions available here)
At the Knoppix Boot Prompt (See Fig. 3 below) enter: knoppix lang=us to start boot Knoppix using the english locale. If you understand German, feel free to just hit 'Enter' to boot into Knoppix.
Once the system finishes booting, press <Ctrl> + <Alt> + <F1> (The Control, Alt and F1 key together) to switch to a virtual terminal.
Type mkdir mountplace to create a directory called 'mountplace'. This is where we will mount the filesystem.
Type mount /dev/hdaX mountplace, where /dev/hdaX is your root partition. More information on Linux partitions is available here.

PS: at grub when I entered root
it gave me this
(hd0,0): filesystem type is ext2fs, partition type 0x03

thanks
0
 
syedasimmeesaqAuthor Commented:
ok I did this

$ fdisk -l /dev/hda

and it told me I had /dev/hda1  boot
                                /dev/hda2 (largest volume)
 and /dev/hda3 (swap)

so I went to mount hda2 and followed these directions but no luck



Reboot the system and configure it to boot from the live CD (instructions available here)
At the Knoppix Boot Prompt (See Fig. 3 below) enter: live lang=us to start boot Knoppix using the english locale. If you understand German, feel free to just hit 'Enter' to boot into Knoppix.
Once the system finishes booting, press <Ctrl> + <Alt> + <F1> (The Control, Alt and F1 key together) to switch to a virtual terminal.
Type mkdir mountplace to create a directory called 'mountplace'. This is where we will mount the filesystem.
Type mount /dev/hdaX mountplace, where /dev/hdaX is your root partition. More information on Linux partitions is available here.
Change to the "/etc" directory on your root partition by typing cd mountplace/etc.
Use your favorite text editor and open the 'shadow' file for editing. I use 'vi', so I type vi shadow (If you have a really old system, you won't have a shadow file, in which case you need to edit the 'passwd' file.)
Scroll down to the line containing the root user's information, which looks something like:
root:dsfDSDF!s:12581:0:99999:7:::
make needed change
Save the file and exit your editor.
Type cd to return to your home directory.
Type umount mountplace to unmount the partition.
Type reboot to reboot your system, and remove the live CD from the drive.
Now you can log into your system as root with no password. Make sure you change the password immediately.
0
 
syedasimmeesaqAuthor Commented:
aaah I think I got it.

I was doing cd etc instead of cd mountplace/etc

and I had to use hda2 as it was the root partition and had all data on it

thanks!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 10
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now