# 02-B.10: Users: Create, Modify, and Delete - Edit /etc/passwd File


## Modify /etc/passwd and /etc/Group Files

### The vipw Command

The vipw command edits the files /etc/passwd. The command sets appropriate locks to prevent corruption by others attempting to make changes to the file during the editing session. The programs attempt to determine the proper editor, by first trying the environment variable $VISUAL, then the environment variable$EDITOR, and finally the default editor which is vi.

Syntax:

vipw [ OPTION ]


NOTICE: the user does NOT specify a filename...there are no arguments.

Command Options:

Options Option Meaning
-g, --group Edit group database.
-h, --help Display help message and exit.
-p, --passwd Edit passwd database.
-q, --quiet Quiet mode.
-R, --root CHROOT_DIR Apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory.

To safely edit the /etc/password file, simply run:

pbmac@pbmac-server $sudo vipw The password will not get updated until you exit the vipw command. This ensures that other users can not inadvertently or intentionally make any changes in /etc/passwd file while you're editing them as root. The vipw command also ensures that once the /etc/passwd is closed, the shadow password file is automatically updated successfully. You can also login as normal user and try to change the the user's password in another Terminal window. The password will not change until you close the vipw command. You can't even create any new users while editing /etc/passwd file vipw command. As stated above, the vipw command will lock the /etc/passwd file and prevent other users from making any changes. It is also possible to make the necessary changes using the useradd, the usermod, and the userdel commands to add, change, and delete users on the system. We have previously talked about the useradd command. ### The usermod Command The usermod command allows for certain changes and modifications be made to a user's information from the command line. Syntax: usermod [ OPTIONS ] USER_LOGIN  Command Options: Options Option Meaning -d, --home HOME_DIR The user's new login directory. If the -m option is given, the contents of the current home directory will be moved to the new home directory, which is created if it does not already exist. -e, --expiredate EXPIRE_DATE The date on which the user account will be disabled. The date is specified in the format YYYY-MM-DD. -f, --inactive INACTIVE The number of days after a password expires until the account is permanently disabled. A value of 0 disables the account as soon as the password has expired, and a value of -1 disables the feature. -g, --gid GROUP The group name or number of the user's new initial login group. The group must exist. -G, --groups GROUP1[,GROUP2,...[,GROUPN]]] A list of supplementary groups which the user is also a member of. Each group is separated from the next by a comma, with no intervening whitespace. The groups are subject to the same restrictions as the group given with the -g option. A simple example would be the changing of a user;'s home directory: pbmac@pbmac-server$ usermode -d /home/manav test_user

The following video discusses the use of the usermod command, with some examples of how it can be used from the command line.

### The userdel Command

The userdel command in Linux system is used to delete a user account and related files. This command basically modifies the system account files, deleting all the entries which refer to the username LOGIN. It is a low-level utility for removing the users.

Syntax:

userdel [ OPTIONS ] USER_LOGIN


Command Options:

Options Option Meaning
-f, --force This option forces the removal of the user account, even if the user is still logged in.
-r, --remove Files in the user's home directory will be removed along with the home directory itself and the user's mail spool. Files located in other file systems will have to be searched for and deleted manually.

With few options the command is quite simple:

pbmac@pbmac-server \$ userdel -f pbmac


This will force the user pbmac to be removed from the system.

A discussion with examples regarding the use of the userdel command. The implications of not deleting users is covered in this video as well.