LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Accidentally cleared the password file (https://www.linuxquestions.org/questions/linux-general-1/accidentally-cleared-the-password-file-48181/)

ForumKid 03-04-2003 06:42 AM

Accidentally cleared the password file
 
OK..Made a big mistake. I accidentally cleared the password file. Cant sign on as root cause it says no such user. I realized what I did so I created a quick account. But the account has no priveledges. How can I recreate the entries in the password file so I can regain control of this redhat box? Im sure there is a way, but I havent the foggiest idea...

Thanks in advance as always :confused:

ranger_nemo 03-04-2003 06:48 AM

If it boots up with LILO, when it says "boot:", type in "linux single", or single after whatever your normal title is.

If it boots up with GRUB, select the linux entry, and type "e" to edit. Select the line that starts with "kernel", and type "e", again. At the end of the line, add a space and "single". Hit [enter] to get back to the main GRUB menu, and type "b" to boot.

This will boot you into single-user mode. It's a runlevel for root to do system maintenance. It is one user / no network, and doesn't need a password, for just such emergencies. When it's in runlevel one, you can passwd username for your accounts.

If you use GRUB, you might have to re-edit as above to remove the "single" to boot to your normal runlevel.

nxny 03-04-2003 06:51 AM

Boot from INSTALL DISK #1, type in 'linux rescue' and mount your root filesystem. See if you have a passwd.OLD in your system. If you do, you can copy it to /etc/passwd. If not, create a simple entry in /etc/passwd for root so you can boot your system and login. I'm assuming you're using shadow passwords and that your /etc/shadow is intact. Please update your profile with the distro you're using.

root:x:0:0:root:/root:/bin/bash

acid_kewpie 03-04-2003 06:57 AM

booting into single mode will not help the situation, as the password file no longer exists, and so neither do a whole bunch of system users etc...

you might be able to get away with trying to re-write it, but it's a hell of a chore, seeing as an average system will have 40 or so system users (for mail daemons, rpm etc...)

ForumKid 03-04-2003 06:59 AM

Hi,

Thanks for all the advice..I have two exact same boxes. Can I copy the password file from the server thats not messed up and copy to the messed up server. I think I can, but will not have the authority on the messed up server.....

nxny 03-04-2003 02:53 PM

Sure you can. If you're sure they have almost identical setups. By doing so, you will replicate the users you have on your _good_ server. I would suggest syncing up /etc/shadow too, just so there wont be users without passwords or vice-versa. That will replicate the user passwords too. If you intend to change the user passwords, you may do so by logging in as root.. preferably in single user mode so as to keep other people away during those few minutes.

ForumKid 03-04-2003 02:57 PM

OK thanks so much once again. One last question. Will I have the authority to do the copy? Im just trying to cover all ends before I do this. Im assuming single user mode will allow me to access the box with root access even though there is no password.

Thanks for the information on the shadow file. ill copy that one too.....

Thanks

nxny 03-04-2003 03:37 PM

>Will I have the authority to do the copy? Im just trying to cover all ends before I do this. Im assuming single user mode will allow me to access the box with root access even though there is no password.

Nope, single user mode assumes that there is a /etc/passwd and that there is a root entry in it. As I'd suggested in an earlier post, you'll have to boot into linux from a rescue-cd or similar, mount your root filesystem, copy the files from a floppy or similar ( assuming that you have the files needed copied to the floppy from the good server). Unlike single user mode, the rescue mode uses a _different_ root filesystem and hence looks up a different /etc/passwd to log you in and do your stuff.

WeNdeL 03-04-2003 04:01 PM

doh...

way to help the man... :D


All times are GMT -5. The time now is 11:28 AM.