Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

vipw

Edit /etc/passwd (vipw) or /etc/group (vigr) safely by hand, with a lock.

Level
Everyday Linux
Group
Users and groups
Needs root
Yes
Package
shadow-utils
Also called
vigr

What it does

vipw and vigr open a copy of the account file in your editor ($VISUAL, $EDITOR or vi) and lock the file, so passwd, useradd and others cannot change it at the same time. When you save, the copy replaces the real file.

After editing /etc/passwd you are asked to edit /etc/shadow too (and after /etc/group also /etc/gshadow), so both stay in sync.

Most work is easier and safer with useradd, usermod and groupmod. Use vipw/vigr for fixes those tools cannot do.

How to write it

vipw [OPTION]...
vigr [OPTION]...

Options 6

Most used

-p, --passwd
Edit the passwd file (default of vipw).
-g, --group
Edit the group file (default of vigr).
-s, --shadow
Edit the shadow file (/etc/shadow or /etc/gshadow).
-q, --quiet
Quiet mode.
-R, --root DIR
Work in this chroot folder.
-h, --help
Show help.

Examples 11

$ run as a normal user# run as root (or with sudo)

  1. 1Edit the user file

    vipw

    Opens /etc/passwd with a lock; afterwards it offers to edit /etc/shadow.

  2. 2Edit the group file

    vigr

    Opens /etc/group with a lock.

  3. 3Edit the shadow file directly

    vipw -s

    For example to fix a wrong aging field.

  4. 4Edit the group shadow file

    vigr -s

    Group passwords and group admins.

  5. 5Use nano as the editor

    EDITOR=nano vipw

    Any editor works.

  6. 6Check the files after a manual edit

    pwck -r; grpck -r

    -r = only report, change nothing.

  7. 7Fix a wrong login shell by hand

    vipw

    Change the last field, for example /bin/bsh back to /bin/bash.

  8. 8Find a second root account (security)

    awk -F: '$3 == 0 {print $1}' /etc/passwd
    root

    Only root may have UID 0. Another name here means a backdoor.

  9. 9Find accounts without a password hash (security)

    awk -F: '$2 == "" {print $1}' /etc/shadow

    Empty field = login without a password. Fix it at once.

  10. 10Make a backup before a manual edit

    cp -a /etc/passwd /etc/shadow /etc/group /root/

    The tools also keep a copy: /etc/passwd- and /etc/group-.

  11. 11See the lock files during an edit

    ls /etc/*.lock

    /etc/passwd.lock exists while vipw is open.

Watch out

  • Never edit /etc/passwd or /etc/shadow with a normal editor while the system runs.
  • A broken line can stop logins for everybody. Keep a root shell open while you test.

Files

/etc/passwd, /etc/shadow, /etc/group, /etc/gshadow
The files that are edited.
/etc/passwd-, /etc/group-
Backup copies from the last change.

Exit codes

0Done.
1Error (file busy or the editor failed).

Full manual

This page explains the command in simple words. The original manual has every detail.

In your terminal: man 8 vipw