How to safely edit /etc/passwd , /etc/shadow and /etc/group in Linux

Do not edit the /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow by hand !!!

Watch Free Movies

If a user tries to change it’s account / group info while root is editing the files by hand (ex: vim /etc/passwd), the /etc files will not pe updated and so, the normal user’s modifications will be discarded.

But there is a way for editing the 4 files safely:

$ sudo vipw opens the /etc/passwd file

$ sudo vipw -s opens the /etc/shadow file

$ sudo vigr opens the /etc/group file

$ sudo vigr -s opens the /etc/gshadow file

While you are editing the corespondent /etc files with vipw / vigr , those files will be locked and a normal user will not be able to change it’s user/group accout info until root exited the /etc configuration file.

The vipw and vigr tools also created some backup files in /etc called passwd- , shadow-, group- and gshadow- with the same permissions and ownership as the originals.

Scroll to Top