Linux Vipw and Vigr Commands Explained

Linux TLDR
Last Updated:
Reading time: 3 minutes

In Linux, you use the useradd, passwd, usermod, and gpasswd commands to modify users or group-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
OS CompatibilityUbuntu, Manjaro, Fedora, etc.
Prerequisitesvipw, vigr
Internet RequiredNo

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 β€œ$EDITOR” environment 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 arguments.

$ 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

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

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 user or group 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.