.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "usermod 3pm" .TH usermod 3pm "2022-10-15" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Linux::usermod \- modify user and group accounts .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& 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"; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module adds, removes and modify user and group accounts according to the passwd and shadow files syntax (like struct passwd from pwd.h). It is not necessary those accounts to be system as long as \f(CW$Linux::usermod::file_passwd\fR, \f(CW$Linux::usermod::file_shadow\fR, \&\f(CW$Linux::usermod::file_group\fR, \f(CW$Linux::usermod::file_gshadow\fR are not in \*(L"/etc\*(R" directory. .SH "METHODS" .IX Header "METHODS" .IP "new" 8 .IX Item "new" .Vb 2 \& Linux::usermod\->new(username) \& Linux::usermod\->new(grpname, 1) .Ve .Sp If group object second 'true' argument must be given .IP "add" 8 .IX Item "add" (username, ...) Class method \- add new user account; arguments are optional, except username; they may be (username, password, uid, gid, comment, home, shell) .IP "del" 8 .IX Item "del" (username) Class method \- removes user account .IP "tobsd" 8 .IX Item "tobsd" converts user fields in shadow / master.passwd file to bsd style .IP "get" 8 .IX Item "get" if used with user object returns one of the following fields: .Sp .Vb 10 \& \*(Aqname\*(Aq or 0 The user\*(Aqs name \& \*(Aqppassword\*(Aq or 1 The "passwd" file password \& \*(Aquid\*(Aq or 2 The user\*(Aqs id \& \*(Aqgid\*(Aq or 3 The user\*(Aqs group id \& \*(Aqcomment\*(Aq or 4 The comment about the user (real username) \& \*(Aqhome\*(Aq or 5 The user\*(Aqs home directory \& \*(Aqshell\*(Aq or 6 The user\*(Aqs shell \& \*(Aqsname\*(Aq or 7 The user\*(Aqs name in shadow file \& \*(Aqpassword\*(Aq or 8 The 13\-character encoded password \& \*(Aqlastchg\*(Aq or 9 The number of days since January 1, 1970 of the last password changed date \& \*(Aqmin\*(Aq or 10 The minimum number of days required between password changes \& \*(Aqmax\*(Aq or 11 The maximum number of days the password is valid \& \*(Aqwarn\*(Aq or 12 The number of days before expiring the password that the user is warned \& \*(Aqinactive\*(Aq or 13 The number of days of inactivity allowed for the user \& \*(Aqexpire\*(Aq or 14 The number of days since January 1, 1970 that account is disabled \& \*(Aqflag\*(Aq or 15 Currently not used .Ve .Sp if used with group object returns one of the following fields: .Sp .Vb 8 \& \*(Aqname\*(Aq or 0 The group name \& \*(Aqppassword\*(Aq or 1 The group password \& \*(Aqgid\*(Aq or 2 The group id number \& \*(Aqusers\*(Aq or 3 The group members (users) \& \*(Aqsname\*(Aq or 4 The group name in gshadow file (the same as \*(Aqname\*(Aq) \& \*(Aqpassword\*(Aq or 5 The encrypted group password \& \*(Aqga\*(Aq or 6 The group administrators \& \*(Aqgu\*(Aq or 7 The group members (users) (the same as \*(Aqusers\*(Aq) .Ve .Sp argument can be either string or number .IP "set" 8 .IX Item "set" (field) .Sp set a field which must be string of characters: .Sp .Vb 2 \& @user_fields = Linux::usermod\->fields; #user fields \& @group_fields = Linux::usermod\->gfields; #group fields .Ve .IP "grpadd" 8 .IX Item "grpadd" (groupname) .IP "grpdel" 8 .IX Item "grpdel" (groupname) .IP "lock" 8 .IX Item "lock" (username) Lock user account (puts '!' at the beginning of the encoded password) .IP "unlock" 8 .IX Item "unlock" (username) Unlock user account (removes '!' from the beginning of the encoded password) .IP "users" 8 .IX Item "users" Class method \- return hash which keys are all users, taken from \f(CW$file_passwd\fR .IP "grps" 8 .IX Item "grps" Class method \- return hash which keys are all groups, taken from \f(CW$file_group\fR .SH "FILES" .IX Header "FILES" /etc/passwd /etc/shadow /etc/group /etc/gshadow .PP unless given your own passwd, shadow, group, gshadow files which must be created .SH "TO DO" .IX Header "TO DO" Groups and user accounts consistency checks .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBgetpwent\fR\|(3), \fBgetpwnam\fR\|(3), \fBusermod\fR\|(8), \fBpasswd\fR\|(1), \fBgpasswd\fR\|(1) .SH "BUGS" .IX Header "BUGS" None known. Report any to author. .SH "AUTHOR" .IX Header "AUTHOR" Vidul Petrov, vidul@abv.bg .PP (C) 2004 Vidul Petrov. All rights reserved. .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.