How to edit /etc/passwd file?

QuestionsQuestions8 SkillsProUser Account ManagementOct, 18 2025
0195

To edit the /etc/passwd file, you need superuser (root) privileges. Here are the steps to do so using a text editor like nano or vim:

Using Nano

  1. Open a terminal.
  2. Use the following command to edit the file with nano:
    sudo nano /etc/passwd
  3. Make the necessary changes.
  4. Save the changes by pressing CTRL + O, then press Enter.
  5. Exit nano by pressing CTRL + X.

Using Vim

  1. Open a terminal.
  2. Use the following command to edit the file with vim:
    sudo vim /etc/passwd
  3. Press i to enter insert mode and make your changes.
  4. Press ESC to exit insert mode.
  5. Type :wq and press Enter to save and exit.

Important Note

Editing the /etc/passwd file can affect user accounts and system functionality. Ensure you know what changes you are making and consider backing up the file before editing:

sudo cp /etc/passwd /etc/passwd.bak

This way, you can restore the original file if needed.

0 Comments

no data
Be the first to share your comment!