accidentally moved /etc/passwd file
I was writing a backup script and accidentally used
"mv /etc/passwd /home/backup" I should have used "cp" I know. I still have a ssh shell into this box but I am not root, and i cannot su or sudo since the passwd file does not have my user id there. How do i recover from this situation without replacing this box? Thanks. Michael |
@ Reply
Hi mliu5715k,
Welcome to LQ!!! Try this: Code:
cp /home/backup /home/passwd Code:
cp /home/passwd /etc/ |
If you have physical access to the box, use a live cd and copy the file back.
@T3RM1NVT0R Since he has no root access, he won't be able to copy to /etc Kind regards |
that won't work because only root can write or copy files to /etc
cp passwd /etc/ cp: cannot create regular file `/etc/passwd': Permission denied |
read a thread about booting into single user mode and change password. will give that a try via ilo
|
@ Reply
Sorry guys in a hurry didnt realize that.
Then you should go with repo's suggestion that is using live CD. But you said that you are ssh into this machine which make me think that you are not at the same location where the machine is. If that is the case you need to go there where the machine is. If you are going in single user mode then make sure you remount the file system with rw otherwise you wont be able to write |
"live CD"? the one that came from manufacture?
|
In general every linux CD has an option to boot as a live CD, so you can access the filesystem on your HD and make changes if needed.
Linux will run from the CD. I always use puppy, it's fast and straight forward. http://www.puppylinux.com/download/index.html Kind regards |
@ Reply
Nope. There are various distribution which comes in live CD. Live CD are there so that you can test the distribution without even installing them like for Ubuntu, Linux Mint, OpenSuSE etc.
It appears that you are using Red Hat. You can use manfacturer's CD for repairing, though idea of going into single user mode worth a try. |
here is my hope:
1. go there in person and boot in single user mode. 2. change root password in single user mode. 3. this will generate a new passwd file with nothing but a root user with the new password. 4. boot up normally, copy back my passwd file the CD solution is a good idea, but i am not sure I can find this particular CD. Thanks all. |
i want to prepare for the live CD method as well.
does the "puppy" CD work for redhat as well? it's generic at this point. is it? Thanks! |
The puppy live CD (like any other live CD) is a separate linux distribution, it will run completely from CD.
Puppy will run completely in RAM. It has nothing to do with whatever is installed on the HD Once loaded, you can mount the HD, and make any changes you want. Kind regards |
thanks Repo, by the same token, my bootable usb stick that has ubuntu would also work?
so long it allows me to mount the hard drive and make changes to /etc/passwd? |
yes
Kind regards |
I had the problem fixed, but i wanted to give you an update and also wanted to thank you all for helping me with the solution. I went with the Single User mode and did it all from ILO, but I am sure the other way would have worked too.
Steps to boot Red Hat into Single User mode: 1. Log into iLO and reboot 2. While booting, watch for the red hat page. This is after the HP RAID stuff 3. Press “e” 4. The boot loader will come up. you get something like this on the screen: root (hd0,0) kernel /vmlinuz-2.6.18-164.el5 ro root=/dev/VolGroup00/root rhgb quiet initrd /initrd-2.6.18-164.el5.img 5. Move the cursor to the second line. (you have to use the console with the java VM or you can’t move the cursor up and down. This is the 3rd console choice) 6. At the end of the line, after “quite”, append “single”, there is a space between the two words 7. press letter “b” to boot 8. you will go into SU mode when you see “sh-3.00#” 9. restore /etc/passwd file and reboot |
All times are GMT -5. The time now is 07:15 PM. |