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 !!!

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.

Liked it? Take a second to support Geekster on Patreon!
Tagged with: , , , , , , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Support LinuxG via Patreon
Support LinuxG.net on Patreon!
Subscribe

  

Subscribe to get the latest Linux news and how to guides directly on your e-mail!