usermod(3pm)
π usermod β the Linux::usermod era π
okay bestie, sit DOWN, because we're talking about usermod, from the 3pm manual section (that's Perl-user-contributed-documentation, iykyk). She's a Perl module named Linux::usermod and she is here to modify user and group accounts. Slay.
β¨ NAME β¨
Linux::usermod β modify user and group accounts π«Ά
πΈ SYNOPSIS πΈ
Here's the whole vibe, verbatim, no notes:
use Linux::usermod;
$user = Linux::usermod->new(username);
$grp = Linux::usermod->new(groupname, 1);
$user->get(gid); # equal to $user->get(3);
$user->get(uid); # equal to $user->get(2);
$grp->get(gid); # equal to $user->get(2);
$grp->get(users);# equal to $user->get(3);
#lock and unlock user account
$user->lock();
$user->unlock();
#get password(passwd file)
$user->get(ppassword);
#get encoded password(shadow file)
$user->get(password);
#set encoded password
$user->set(password);
$grp->set(password);
#set shell / group administrator
$user->set(shell);
$grp->set(ga);
#set group users
@users = qw(user1 user2);
$grp->set(users, "@users");
Linux::usermod->add(username);
#or
Linux::usermod->add(username, password, uid, gid, comment, home, shell);
#where the password goes in shadow file and gid becomes
#equal to uid unless specified and uid is becoming the
#first unreserved number after 1000 unless specified
#or
@users = qw(user1 user2 user3);
Linux::usermod->grpadd(groupname, gid, "@users")
#where the password goes in gshadow file and gid becomes
#equal to the second argument or the first unreserved number
#after 100
#delete user/group
Linux::usermod->del(username);
Linux::usermod->grpdel(groupname);
#all fields are returned from the class methods fields/gfields
print $user->get($_) for (Linux::usermod->fields);
print $grp->get($_) for (Linux::usermod->gfields);
#set working passwd and shadow files
#$Linux::usermod::file_passwd = "./my_passwd";
#$Linux::usermod::file_shadow = "./my_shadow";
#$Linux::usermod::file_group = "./my_group";
#$Linux::usermod::file_gshadow= "./my_gshadow";
π¦ DESCRIPTION π¦
So what does she actually DO? This module adds, removes and modifies user and group accounts, following the passwd and shadow file syntax β like struct passwd from pwd.h, if you speak C. π
And here's the part that's honestly iconic: those accounts do not have to be system accounts, as long as $Linux::usermod::file_passwd, $Linux::usermod::file_shadow, $Linux::usermod::file_group and $Linux::usermod::file_gshadow are not sitting in the "/etc" directory. Do your own thing, bestie. π
π METHODS π
new
Linux::usermod->new(username)
Linux::usermod->new(grpname, 1)
If you want a group object, that second 'true' argument is non-negotiable β it must be given. π«‘
add
(username, ...) β class method, adds a shiny new user account. The arguments are optional, except username. They may be:
(username, password, uid, gid, comment, home, shell)
del
(username) β class method, removes a user account. bye bestie π
tobsd
converts user fields in shadow / master.passwd file to bsd style π
get
If you call her on a user object, you get back one of these fields:
'name'or0β The user's name'ppassword'or1β Thepasswdfile password'uid'or2β The user's id'gid'or3β The user's group id'comment'or4β The comment about the user (real username)'home'or5β The user's home directory'shell'or6β The user's shell'sname'or7β The user's name in shadow file'password'or8β The 13-character encoded password'lastchg'or9β The number of days since January 1, 1970 of the last password changed date'min'or10β The minimum number of days required between password changes'max'or11β The maximum number of days the password is valid'warn'or12β The number of days before expiring the password that the user is warned'inactive'or13β The number of days of inactivity allowed for the user'expire'or14β The number of days since January 1, 1970 that account is disabled'flag'or15β Currently not used π
If you call her on a group object instead, you get one of these:
'name'or0β The group name'ppassword'or1β The group password'gid'or2β The group id number'users'or3β The group members (users)'sname'or4β The group name in gshadow file (the same as'name')'password'or5β The encrypted group password'ga'or6β The group administrators'gu'or7β The group members (users) (the same as'users')
and your argument can be either a string or a number, so do whatever feels right β¨
set
(field)
sets a field, which must be a string of characters:
@user_fields = Linux::usermod->fields; #user fields
@group_fields = Linux::usermod->gfields; #group fields
grpadd
(groupname)
grpdel
(groupname)
lock
(username) β locks the user account (puts '!' at the beginning of the encoded password) π
unlock
(username) β unlocks the user account (removes '!' from the beginning of the encoded password) π
users
Class method β returns a hash whose keys are all users, taken from $file_passwd.
grps
Class method β returns a hash whose keys are all groups, taken from $file_group. π
π FILES π
/etc/passwd /etc/shadow /etc/group /etc/gshadow
unless you bring your own passwd, shadow, group, gshadow files β which, heads up, must be created. π§
π TO DO π
Groups and user accounts consistency checks. (manifesting this for her π―οΈ)
π SEE ALSO π
getpwent(3), getpwnam(3), usermod(8), passwd(1), gpasswd(1)
π BUGS π
None known. Report any to author. (if you find one, do NOT gatekeep, tell her)
π AUTHOR π
Vidul Petrov, vidul@abv.bg
(C) 2004 Vidul Petrov. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
okay and finally, the little receipts at the bottom: this whole thing is from perl v5.36.0, dated 2022-10-15, filed under usermod(3pm). periodt π
β¨π
π¦ where this page comes from
- ubuntu noble: liblinux-usermod-perl 0.69-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: liblinux-usermod-perl 0.69-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: liblinux-usermod-perl 0.69-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms