LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   accidentally moved /etc/passwd file (https://www.linuxquestions.org/questions/linux-server-73/accidentally-moved-etc-passwd-file-924066/)

mliu5715k 01-16-2012 12:42 PM

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

T3RM1NVT0R 01-16-2012 12:55 PM

@ Reply
 
Hi mliu5715k,

Welcome to LQ!!!

Try this:

Code:

cp /home/backup /home/passwd
and then:

Code:

cp /home/passwd /etc/

repo 01-16-2012 12:59 PM

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

mliu5715k 01-16-2012 01:01 PM

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

mliu5715k 01-16-2012 01:06 PM

read a thread about booting into single user mode and change password. will give that a try via ilo

T3RM1NVT0R 01-16-2012 01:11 PM

@ 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

mliu5715k 01-16-2012 01:18 PM

"live CD"? the one that came from manufacture?

repo 01-16-2012 01:22 PM

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

T3RM1NVT0R 01-16-2012 01:22 PM

@ 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.

mliu5715k 01-16-2012 01:34 PM

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.

mliu5715k 01-16-2012 03:54 PM

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!

repo 01-16-2012 03:58 PM

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

mliu5715k 01-16-2012 04:18 PM

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?

repo 01-16-2012 04:19 PM

yes

Kind regards

mliu5715k 01-17-2012 04:00 PM

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.