Have you accidentally deleted the passwd and shadow files in your Ubuntu system? Don't panic! In this article, we will guide you through the process of fixing this issue step by step. But before we begin, let's understand what these files are and why they are important.
Understanding passwd and shadow Files
The passwd and shadow files are crucial system files in Ubuntu that store user account information. The passwd file contains the basic user account details such as username, user ID, group ID, home directory, and login shell. On the other hand, the shadow file stores the encrypted passwords for the user accounts.
Without these files, you won't be able to log in to your Ubuntu system or access any of your user accounts. So, it's essential to restore or recreate these files if they get accidentally deleted.
Restoring Deleted passwd and shadow Files
Here's a step-by-step guide to help you restore the deleted passwd and shadow files in Ubuntu:
- Boot your Ubuntu system and open a terminal. You can do this by pressing
Ctrl+Alt+Ton your keyboard. - Once the terminal is open, type the following command to switch to the root user:
sudo su
- Next, navigate to the
/etcdirectory using the following command:
cd /etc
- Now, check if you have a backup of the passwd and shadow files. If you do, you can simply restore them from the backup. Use the following command to list the available backups:
ls -l passwd* shadow*
- If you find a backup, use the
cpcommand to restore the files. For example, if the backup file is namedpasswd.backup, run the following command:
cp passwd.backup passwd
- Repeat the same command for the shadow file:
cp shadow.backup shadow
- If you don't have a backup, don't worry. You can recreate the passwd and shadow files manually. Run the following command to generate a new passwd file:
pwconv
- Next, use the
passwdcommand to set a new password for the root user:
passwd root
- Finally, reboot your system using the following command:
reboot
After the reboot, you should be able to log in to your Ubuntu system and access your user accounts as usual.
Conclusion
Accidentally deleting the passwd and shadow files in Ubuntu can be a frustrating experience, but it's not the end of the world. By following the steps outlined in this article, you can easily restore or recreate these files and regain access to your system.
References
| Source | Link |
|---|---|
| Ubuntu Documentation | https://help.ubuntu.com/community/LostPassword |
| Linuxize | https://linuxize.com/post/how-to-recover-a-deleted-file-in-linux/ |