PasswdFile(3pm)
π NAME π
okay so bestie, <pink>Unix::PasswdFile</pink> β it's the Perl interface to /etc/passwd format files. that's it, that's the whole vibe β¨
πΈ SYNOPSIS πΈ
use Unix::PasswdFile;
$pw = new Unix::PasswdFile "/etc/passwd";
$pw->user("joeblow", $pw->encpass("secret"), $pw->maxuid + 1, 10,
"Joe Blow", "/export/home/joeblow", "/bin/ksh");
$pw->delete("deadguy");
$pw->passwd("johndoe", $pw->encpass("newpass"));
foreach $user ($pw->users) {
print "Username: $user, Full Name: ", $pw->gecos($user), "\n";
}
$pw->commit();
undef $pw;
like literally just look at it. she's serving π«Ά
π¦ DESCRIPTION π¦
so the <cyan>Unix::PasswdFile</cyan> module hands you an abstract interface to files in /etc/passwd format. she does the unglamorous stuff for you, no cap: file locking, getting colons in the right places, and every other tiny niggling little detail you do NOT want to be hand-formatting at 2am π
it's giving "let me handle it bestie" energy. periodt.
π METHODS π
π
commit( [BACKUPEXT] )
go read the <lavender>Unix::ConfigFile</lavender> documentation for the description of this method, babes. that's where the tea is β
π
delete( USERNAME )
this one deletes the named user. if the user you passed in doesn't exist, it justβ¦ does nothing. no drama, no error, no effect π
π
encpass( PASSWORD )
again, the <lavender>Unix::ConfigFile</lavender> documentation has the full description of this method. go peek β¨
π
gecos( USERNAME [,GECOS] )
reads or modifies a user's GECOS string β which is typically their full name, iykyk. either way, it returns the GECOS string back to you πΈ
π
gid( USERNAME [,GID] )
reads or modifies a user's GID. and yes, it returns the GID in either case π
π
home( USERNAME [,HOMEDIR] )
reads or modifies a user's home directory. returns the home directory either way, always π
π
maxuid( [IGNORE] )
this method returns the maximum UID in use by all users. now if you pass in that optional IGNORE parameter, it'll skip over every UID that's greater than or equal to IGNORE while it's doing the math. super handy for leaving out accounts like nobody, bestie β iconic behaviour honestly π
π
new( FILENAME [,OPTIONS] )
yep, <lavender>Unix::ConfigFile</lavender> documentation, description of this method, go read it π
π
passwd( USERNAME [,PASSWD] )
reads or modifies a user's password, and returns the encrypted password in either case. β οΈ important though: if you've got a plaintext password, use the encpass method to encrypt it first before you hand it to this method. do not skip that step, fr fr π¨
π
rename( OLDNAME, NEWNAME )
this one changes the username for a user π¦. heads up though β if NEWNAME matches a user that already exists, that user will be overwritten. gone. poof. it returns 0 on failure and 1 on success.
π
shell( USERNAME [,SHELL] )
reads or modifies a user's shell. returns the shell in either case π
π
uid( USERNAME [,UID] )
reads or modifies a user's UID. returns the UID in either case β
π
user( USERNAME [,PASSWD, UID, GID, GECOS, HOMEDIR, SHELL] )
okay this is the main character method β¨ she can add, modify, or return information about a user, depending on what you give her.
- give her just the single username parameter and she returns a six element list of
(PASSWORD, UID, GID, GECOS, HOMEDIR, SHELL)β orundefif no such user exists π - give her all seven parameters and the named user gets created, or modified if they already exist. and yes, you still get that same six element list back in this case too π«Ά
π
users( [SORTBY] )
returns a list of all existing usernames π. by default that list is sorted by the UIDs of the users. you can also pass "name" as the parameter to get it sorted by username instead. and in scalar context? this method returns the total number of users. versatile queen π
π AUTHOR π
Steve Snodgrass, ssnodgra@fore.com π
π₯ SEE ALSO π₯
Unix::AliasFile, Unix::AutomountFile, Unix::ConfigFile, Unix::GroupFile
and that's the whole page bestie, no notes π
this was perl v5.32.1, dated 2021-08-21, and it's the <rainbow>PasswdFile(3pm)</rainbow> page from the User Contributed Perl Documentation β go forth and manage those users, you absolute icon ππβ¨
π¦ where this page comes from
- debian bookworm: libunix-configfile-perl 0.6-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libunix-configfile-perl 0.6-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libunix-configfile-perl 0.6-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libunix-configfile-perl 0.6-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libunix-configfile-perl 0.6-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libunix-configfile-perl 0.6-3 Β· 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