The best way to edit /etc/passwd, or shadow or group file is to use vipw command. Traditionally (under UNIX and Linux) if you use vi to edit /etc/passwd file and same time a user try to change a password while root editing file, then the user's change will not entered into file. To avoid this problem and to put a lock while editing file, use vipw and vigr command which will edit the files /etc/passwd and /etc/group respectively. If you pass -s option to these command, then they will edit the shadow versions of those files i.e. /etc/shadow and /etc/gshadow, respectively.
The main purpose of locks is to prevent file corruption. Do not use vi or other text editor to edit password file. Syntax:
- vipw -s : Edit /etc/passwd file
- vigr -s : Edit /etc/group file
Where,
- -s : Secure file editing
An example
Login as a root user:
# vipw -s
On other terminal login as normal user (for example vivek) and issue command passwd to change vivek’s password:
$ passwd
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: Authentication token lock busy
As you see it returned with an error "passwd: Authentication token lock busy"
This will avoid /etc/shadow file corruption.
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins

- My 10 UNIX Command Line Mistakes
- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
Facebook it - Tweet it - Print it -
We're here to help you make the most of sysadmin work. So, subscribe!


{ 2 comments… read them below or add one }
Nice tip. thanks.
I think you need a correction in this article.
vipw will edit /etc/passwd file
vigr will edit /etc/group file
AND
vipw -s will edit /etc/shadow file
vigr -s will edit /etc/gshadow file