vipw和vigr命令

时间:2022-11-13 15:01:07

Modifying the Configuration Files

To add user accounts, it suffices that one line is added to /etc/passwd and another line is added to /etc/shadow, in which the user account and all of its properties are defined. It is not recommended, though. By making an error, you might mess up the consistency of the file and make logging in completely impossible to anyone. Also, you might encounter locking problems if one administrator is trying to modify the file contents directly while another administrator wants to write a modification with some tool.

If you insist on modifying the configuration files directly, you should use  vipw . This command opens an editor interface on your configuration files, and more important, it sets the appropriate locks on the configuration files to prevent corruption. It does  not  check syntax, however, so make sure that you know what you are doing because even by making a typo you might still severely mess up your server. If you want to use this tool to modify the /etc/shadow file, use  vipw -s . To edit the contents of the /etc/group file where groups are defined, a similar command with the name   vigr  exists.   
NOTE     It is nice to know that vipw and vigr exist, but it is better not to use these utilities or anything else that opens the user and group configuration files directly. Instead, use tools like useradd and groupmod.

这两个命令最主要就是会给文件加锁!以免在编辑文件时!其他用户也在同时使用文件!而造成其他用户修改的不成功!

vipw 修改/etc/passwd文件

vipw –s  修改/etc/shadow文件

vigr  修改/etc/groups文件

vigr –s 修改/etc/gshadow文件

[root@rhel7 ~]# man vipw
VIPW() System Management Commands VIPW() NAME
vipw, vigr - edit the password, group, shadow-password or shadow-group file SYNOPSIS
vipw [options] vigr [options] DESCRIPTION
The vipw and vigr commands edits the files /etc/passwd and /etc/group, respectively. With the -s flag, they will edit the shadow versions of those files,
/etc/shadow and /etc/gshadow, respectively. The programs will set the appropriate locks to prevent file corruption. When looking for an editor, the
programs will first try the environment variable $VISUAL, then the environment variable $EDITOR, and finally the default editor, vi(). OPTIONS
The options which apply to the vipw and vigr commands are: -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. -s, --shadow
Edit shadow or gshadow database. ENVIRONMENT
VISUAL
Editor to be used. EDITOR
Editor to be used if VISUAL is not set. FILES
/etc/group
Group account information. /etc/gshadow
Secure group account information. /etc/passwd
User account information. /etc/shadow
Secure user account information. SEE ALSO
vi(), group(), gshadow() , passwd(), , shadow(). shadow-utils 4.1.5.1 // VIPW()
Manual page vipw() line / (END) (press h for help or q to quit)