NAME
upf - Manipulate /etc/{passwd,shadow,group,gshadow} entries
VERSION
This document describes version 0.01 of upf (from Perl distribution App-upf), released on 2015-03-06.
SYNOPSIS
Usage:
% upf add-delete-user-groups [options]
% upf add-group [options]
% upf add-user [options]
% upf add-user-to-group [options]
% upf delete-group [options]
% upf delete-user [options]
% upf delete-user-from-group [options]
% upf get-group [options]
% upf get-max-gid [options]
% upf get-max-uid [options]
% upf get-user [options]
% upf get-user-groups [options]
% upf group-exists [options]
% upf is-member [options]
% upf list-groups [options]
% upf list-users [options]
% upf list-users-and-groups [options]
% upf modify-group [options]
% upf modify-user [options]
% upf set-user-groups [options]
% upf set-user-password [options]
% upf user-exists [options]
SUBCOMMANDS
add-delete-user-groups
Add or delete user from one or several groups.
This can be used to reduce several add_user_to_group()
and/or delete_user_from_group()
calls to a single call. So:
add_delete_user_groups(user=>'u',add_to=>['a','b'],delete_from=>['c','d']);
is equivalent to:
add_user_to_group (user=>'u', group=>'a');
add_user_to_group (user=>'u', group=>'b');
delete_user_from_group(user=>'u', group=>'c');
delete_user_from_group(user=>'u', group=>'d');
except that add_delete_user_groups()
does it in one pass.
add-group
Add a new group.
add-user
Add a new user.
add-user-to-group
Add user to a group.
delete-group
Delete a group.
delete-user
Delete a user.
delete-user-from-group
Delete user from a group.
get-group
Get group details by group name or gid.
Either group
OR gid
must be specified.
The function is not dissimilar to Unix's getgrnam()
or getgrgid()
.
get-max-gid
Get maximum GID used.
get-max-uid
Get maximum UID used.
get-user
Get user details by username or uid.
Either user
OR uid
must be specified.
The function is not dissimilar to Unix's getpwnam()
or getpwuid()
.
get-user-groups
Return groups which the user belongs to.
group-exists
Check whether group exists.
is-member
Check whether user is member of a group.
list-groups
List Unix groups in group file.
list-users
List Unix users in passwd file.
list-users-and-groups
List Unix users and groups in passwd/group files.
This is basically list_users()
and list_groups()
combined, so you can get both data in a single call. Data is returned in an array. Users list is in the first element, groups list in the second.
modify-group
Modify an existing group.
Specify arguments to modify corresponding fields. Unspecified fields will not be modified.
modify-user
Modify an existing user.
Specify arguments to modify corresponding fields. Unspecified fields will not be modified.
set-user-groups
Set the groups that a user is member of.
set-user-password
Set user's password.
user-exists
Check whether user exists.
OPTIONS
*
marks required options.
Common options
- --config-path=s
-
Set path to configuration file.
Can be specified multiple times.
- --config-profile=s
-
Set configuration profile to use.
- --etc-dir=s
-
Specify location of passwd files.
Default value:
"/etc"
- --format=s
-
Choose output format, e.g. json, text.
- --help, -h, -?
-
Display this help message.
- --json
-
Set output format to json.
- --naked-res
-
When outputing as JSON, strip result envelope.
By default, when outputing as JSON, the full enveloped result is returned, e.g.:
[200,"OK",[1,2,3],{"func.extra"=>4}]
The reason is so you can get the status (1st element), status message (2nd element) as well as result metadata/extra result (4th element) instead of just the result (3rd element). However, sometimes you want just the result, e.g. when you want to pipe the result for more post-processing. In this case you can use `--naked-res` so you just get:
[1,2,3]
- --no-config
-
Do not use any configuration file.
- --subcommands
-
List available subcommands.
- --version, -v
Options for subcommand add-delete-user-groups
- --add-to-json=s
-
List of group names to add the user as member of (JSON-encoded).
See
--add-to
. - --add-to=s@
-
List of group names to add the user as member of.
Default value:
[]
Can be specified multiple times.
- --delete-from-json=s
-
List of group names to remove the user as member of (JSON-encoded).
See
--delete-from
. - --delete-from=s@
-
List of group names to remove the user as member of.
Default value:
[]
Can be specified multiple times.
- --user-json=s
-
See
--user
. - --user=s*
Options for subcommand add-group
- --backup
-
Whether to backup when modifying files.
Backup is written with `.bak` extension in the same directory. Unmodified file will not be backed up. Previous backup will be overwritten.
- --gid-json=s
-
Pick a specific new GID (JSON-encoded).
See
--gid
. - --gid=s
-
Pick a specific new GID.
Adding a new group with duplicate GID is allowed.
- --group-json=s
-
See
--group
. - --group=s*
- --max-gid=i
-
Pick a range for new GID.
Default value:
65535
If a free GID between `min_gid` and `max_gid` is not found, error 412 is returned.
- --members-json=s
-
Fill initial members (JSON-encoded).
See
--members
. - --members=s
-
Fill initial members.
- --min-gid=i
-
Pick a range for new GID.
Default value:
1000
If a free GID between `min_gid` and `max_gid` is not found, error 412 is returned.
Options for subcommand add-user
- --backup
-
Whether to backup when modifying files.
Backup is written with `.bak` extension in the same directory. Unmodified file will not be backed up. Previous backup will be overwritten.
- --encpass=s
-
Encrypted password.
- --expire-date=i
-
The date of expiration of the account, expressed as the number of days since Jan 1, 1970.
- --gecos=s
-
Usually, it contains the full username.
- --gid-json=s
-
Pick a specific GID when creating group (JSON-encoded).
See
--gid
. - --gid=s
-
Pick a specific GID when creating group.
Duplicate GID is allowed.
- --group-json=s
-
Select primary group (default is group with same name as user) (JSON-encoded).
See
--group
. - --group=s
-
Select primary group (default is group with same name as user).
Normally, a user's primary group with group with the same name as user, which will be created if does not already exist. You can pick another group here, which must already exist (and in this case, the group with the same name as user will not be created).
- --home=s
-
User's home directory.
- --last-pwchange=i
-
The date of the last password change, expressed as the number of days since Jan 1, 1970..
- --max-gid-json=s
-
Pick a range for GID when creating group (JSON-encoded).
See
--max-gid
. - --max-gid=s
-
Pick a range for GID when creating group.
- --max-pass-age=i
-
The number of days after which the user will have to change her password.
- --max-uid=i
-
Pick a range for new UID.
Default value:
65535
If a free UID between `min_uid` and `max_uid` is not found, error 412 is returned.
- --min-gid-json=s
-
Pick a range for GID when creating group (JSON-encoded).
See
--min-gid
. - --min-gid=s
-
Pick a range for GID when creating group.
- --min-pass-age=i
-
The number of days the user will have to wait before she will be allowed to change her password again.
- --min-uid=i
-
Pick a range for new UID.
Default value:
1000
If a free UID between `min_uid` and `max_uid` is not found, error 412 is returned.
- --pass-inactive-period=i
-
The number of days after a password has expired (see max_pass_age) during which the password should still be accepted (and user should update her password during the next login).
- --pass-warn-period=i
-
The number of days before a password is going to expire (see max_pass_age) during which the user should be warned.
- --pass=s
-
Password, generally should be "x" which means password is encrypted in shadow.
- --shell=s
-
User's home directory.
- --uid-json=s
-
Pick a specific new UID (JSON-encoded).
See
--uid
. - --uid=s
-
Pick a specific new UID.
Adding a new user with duplicate UID is allowed.
- --user-json=s
-
See
--user
. - --user=s*
Options for subcommand add-user-to-group
Options for subcommand delete-group
- --backup
-
Whether to backup when modifying files.
Backup is written with `.bak` extension in the same directory. Unmodified file will not be backed up. Previous backup will be overwritten.
- --group-json=s
-
See
--group
. - --group=s*
Options for subcommand delete-user
- --backup
-
Whether to backup when modifying files.
Backup is written with `.bak` extension in the same directory. Unmodified file will not be backed up. Previous backup will be overwritten.
- --user-json=s
-
See
--user
. - --user=s*
Options for subcommand delete-user-from-group
Options for subcommand get-group
- --gid=i
- --group=s
- --without-field-names
-
By default, a hashref is returned containing field names and its values, e.g. `{group=>"titin", pass=>"x", gid=>500, ...}`. With `with_field_names=>0`, an arrayref is returned instead: `["titin", "x", 500, ...]`.
Options for subcommand get-max-gid
Options for subcommand get-max-uid
Options for subcommand get-user
- --uid=i
- --user=s
- --without-field-names
-
By default, a hashref is returned containing field names and its values, e.g. `{user=>"titin", pass=>"x", uid=>500, ...}`. With `with_field_names=>0`, an arrayref is returned instead: `["titin", "x", 500, ...]`.
Options for subcommand get-user-groups
- --detail
-
If true, return all fields instead of just group names.
- --user-json=s
-
See
--user
. - --user=s*
- --without-field-names
-
By default, when `detail=>1`, a hashref is returned for each entry containing field names and its values, e.g. `{group=>"titin", pass=>"x", gid=>500, ...}`. With `with_field_names=>0`, an arrayref is returned instead: `["titin", "x", 500, ...]`.
Options for subcommand group-exists
Options for subcommand is-member
Options for subcommand list-groups
- --detail
-
If true, return all fields instead of just group names.
- --without-field-names
-
By default, when `detail=>1`, a hashref is returned for each entry containing field names and its values, e.g. `{group=>"titin", pass=>"x", gid=>500, ...}`. With `with_field_names=>0`, an arrayref is returned instead: `["titin", "x", 500, ...]`.
Options for subcommand list-users
- --detail
-
If true, return all fields instead of just usernames.
- --without-field-names
-
By default, when `detail=>1`, a hashref is returned for each entry containing field names and its values, e.g. `{user=>"titin", pass=>"x", uid=>500, ...}`. With `with_field_names=>0`, an arrayref is returned instead: `["titin", "x", 500, ...]`.
Options for subcommand list-users-and-groups
Options for subcommand modify-group
- --admins=s
-
It must be a comma-separated list of user names, or empty.
- --backup
-
Whether to backup when modifying files.
Backup is written with `.bak` extension in the same directory. Unmodified file will not be backed up. Previous backup will be overwritten.
- --encpass=s
-
Encrypted password.
- --gid=i
-
Numeric group ID.
- --group=s
-
Group name.
- --members=s
-
List of usernames that are members of this group, separated by commas.
- --pass=s
-
Password, generally should be "x" which means password is encrypted in gshadow.
Options for subcommand modify-user
- --backup
-
Whether to backup when modifying files.
Backup is written with `.bak` extension in the same directory. Unmodified file will not be backed up. Previous backup will be overwritten.
- --encpass=s
-
Encrypted password.
- --expire-date=i
-
The date of expiration of the account, expressed as the number of days since Jan 1, 1970.
- --gecos=s
-
Usually, it contains the full username.
- --gid=i
-
Numeric primary group ID for this user.
- --home=s
-
User's home directory.
- --last-pwchange=i
-
The date of the last password change, expressed as the number of days since Jan 1, 1970..
- --max-pass-age=i
-
The number of days after which the user will have to change her password.
- --min-pass-age=i
-
The number of days the user will have to wait before she will be allowed to change her password again.
- --pass-inactive-period=i
-
The number of days after a password has expired (see max_pass_age) during which the password should still be accepted (and user should update her password during the next login).
- --pass-warn-period=i
-
The number of days before a password is going to expire (see max_pass_age) during which the user should be warned.
- --pass=s
-
Password, generally should be "x" which means password is encrypted in shadow.
- --shell=s
-
User's home directory.
- --uid=i
-
Numeric user ID.
- --user=s
-
User (login) name.
Options for subcommand set-user-groups
- --groups-json=s
-
List of group names that user is member of (JSON-encoded).
See
--groups
. - --groups=s@*
-
List of group names that user is member of.
Default value:
[]
Aside from this list, user will not belong to any other group.
Can be specified multiple times.
- --user-json=s
-
See
--user
. - --user=s*
Options for subcommand set-user-password
- --backup
-
Whether to backup when modifying files.
Backup is written with `.bak` extension in the same directory. Unmodified file will not be backed up. Previous backup will be overwritten.
- --pass-json=s
-
See
--pass
. - --pass=s*
- --user-json=s
-
See
--user
. - --user=s*
Options for subcommand user-exists
ENVIRONMENT
UPF_OPT
FILES
~/upf.conf
/etc/upf.conf
COMPLETION
This script has shell tab completion capability with support for several shells.
bash
To activate bash completion for this script, put:
complete -C upf upf
in your bash startup (e.g. ~/.bashrc
). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.
It is recommended, however, that you install shcompgen which allows you to activate completion scripts for several kinds of scripts on multiple shells. Some CPAN distributions (those that are built with Dist::Zilla::Plugin::GenShellCompletion) will even automatically enable shell completion for their included scripts (using shcompgen
) at installation time, so you can immadiately have tab completion.
tcsh
To activate tcsh completion for this script, put:
complete upf 'p/*/`upf`/'
in your tcsh startup (e.g. ~/.tcshrc
). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.
It is also recommended to install shcompgen
(see above).
other shells
For fish and zsh, install shcompgen
as described above.
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/App-upf.
SOURCE
Source repository is at https://github.com/perlancar/perl-App-upf.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-upf
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
AUTHOR
perlancar <perlancar@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2015 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.