Beginners Guide for Vipw and Vigr Commands in Linux

Linux TLDR
Last Updated:
Reading time: 3 minutes

In Linux, you use the useradd, passwd, usermod, and gpasswd commands to modify users or groups related information, like creating them, deleting them, assigning passwords, etc.

Note that these commands only provide you an interface to modify the โ€œ/etc/passwdโ€œ, โ€œ/etc/shadowโ€œ, โ€œ/etc/groupโ€œ, and โ€œ/etc/gshadowโ€ files with safety measures.

But some Linux users, like me, are total freaks and directly modify these files using a text editor instead of using the aforementioned commands, which keeps us safe from file corruption.

Problem with Direct File Modification

Now, you might be wondering whatโ€™s wrong with using the text editor to directly modify these configuration files instead of using the mentioned commands.

Look, when you modify the configuration files using the mentioned commands, there are some safety features in use, like locking the configuration file while you change it.

So, when you modify these configuration files and another user tries to modify the same file, they will not be able to save changes until you close the file to prevent file corruption.

But if you modify this file directly in a text editor, this safety feature doesnโ€™t work, and another user can make changes and save them. This can lead to a corrupted file, which can be very bad if youโ€™re working on a server.

You can still modify this file using your favorite text editor (with safety measures) with the help of the “vipw” or “vigr” commands, which you are about to learn in this article.

Tutorial Details

DescriptionUsage of Vipw and Vigr Commands
Difficulty LevelModerate
Root or Sudo PrivilegesYes
Host System and ArchitectureUbuntu 22.10 (x64)
OS Compatibility Ubuntu, Manjaro, Fedora, etc.
Prerequisitesvipw, vigr
Internet RequiredNo
Discussed Tools in this Article

What are the Vipw and Vigr Commands in Linux?

The “vipw” (stands for “vi password“) and “vigr” (stands for “vi group“) commands are very similar (weโ€™ll discuss their differences later) and use your default text editor (choosing either from the “$VISUAL” or “$EDITORenvironment variables) to safely modify the following configuration files:

  • /etc/passwd“: User account information.
  • /etc/shadow“: Secure user account information.
  • /etc/group“: Group account information.
  • /etc/gshadow“: Secure group account information.

So, when you use the “vipw” and “vigr” commands to modify the above mentioned files, it sets the right locks so that other people canโ€™t mess up the file by trying to change it during the editing session.

Syntax of the Vipw and Vigr Commands

Both commands only accept options as an argument.

$ vipw [OPTION]
$ vigr [OPTION]

Aside from the options listed below, these commands do not require a username.

OptionsDescription
-pEdit the “/etc/passwd” file.
-gEdit the “/etc/group” file.
-qVipw command will edit the “/etc/passwd” file and vigr command will edit the “/etc/group” file in quiet mode.
-RApply changes to the “CHROOT_DIR” directory and use the configuration
files from the “CHROOT_DIR” directory.
-sVipw command will edit the “/etc/shadow” file and vigr command will edit the “/etc/gshadow” file.
-hDisplay the help section.

Difference Between the Vipw and Vigr Commands

The vipw command is specifically designed to modify user related information, while the vigr command is mostly focused on editing group related information.

The options table mentioned their difference, but you should check the following table to know their exact difference.

Vipw commandVigr command
The “-q” flag will modify the “/etc/passwd” file in quiet mode.The “-q” flag will modify the “/etc/group” file in quiet mode.
The “-s” flag will modify the “/etc/shadow” file.The “-s” flag will modify the “/etc/gshadow” file.

Usage of Vipw and Vigr Commands in Linux

There isn’t much to say about this command; simply look through the options table to find the relevant option for your configuration file of interest.

For example, if you are interested in editing the โ€œ/etc/passwdโ€ file, then simply use one of the following commands which will safely open the configuration file in your default text editor.

$ sudo vipw -p

#OR

$ sudo vigr -p

Output:

Editing the "/etc/passwd" file
Editing the “/etc/passwd” file

The best part about using these commands to edit the โ€œ/etc/passwdโ€ file is that if another user tries to modify this file using commands like โ€œuseraddโ€œ, then the command will not be executed until the above configuration file is closed.

Unable to create a user account
Unable to create a user account

Once the configuration file is closed, the above command will run automatically (if there are no errors) to create the user you specified on your Linux system.

So, using both of these commands, you can safely modify the configuration files that they offer to edit using the different options in your favorite text editor.

I hope this article might be useful for you to understand these two unknown (or less known) commands that provide you safety while editing the users or groups configuration files.

If you have more amazing tools like this, then let us know in the comment section.

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.