LnxUser::addUser
Innen: IT documentation
Description
Object-oriented style
public lnxUser::addUser ( array $user ): bool
Procedural style
lnxAddUser ( array $user ): bool
Create a linux user with user parameters.
Parameters
user- Associative array what contains the new user's parameters. Structure of the array: [
'name'=> string- Mantandory! Name of linux user.
'password'=> string- Mantandory! Password of linux user.
'uid'=> int- Optional. User ID of linux user. The ID must not exist!
'gid'=> int | string- Optional. Primary group of the linux user. The group must exist! If this parameter is not present the Group name will be the User name and the Group ID will be the User ID or the first free ID.
'groups'=> array- Optional. Group membership of the linux user. It must be a simple indexed array what contains the groups in what the user will be member. The groups must exist.
'nogroup'=> bool- Optional. If
truethe Primary group will not be created. If'gid'is present this parameter will be ineffective. 'comment'=> string- Optional. Comment (display name) of linux user.
'home'=> string- Optional. Absolute path of Home directory of linux user.
'createhome'=> bool- Optional. If
falsethe Home directory will not be created. 'shell'=> string- Optional. Absolute path of shell for linux user.
'inactive'=> int- Optional. The number of days after password expires that account is disabled.
'expire'=> int- Optional. Date when account will be disabled. Format:
timestamp. 'system'=> bool- Optional. If
truecreate a system account. User ID will be under 1000. If 'uid' is present this parameter will be ineffective. 'nonunique'=> bool- Optional. If
trueallow to create users with duplicate (non-unique) User ID. ]
Return Values
Returns true if user is created, false otherwise.
Changelog
| Version (lnxUser) |
Description |
|---|---|
| 1.00 | available |
Examples
$user = 'testUser';
# Add linux user
if ( ! lnxAddUser( [
'name' => $user, // Mantandory! Name of linux user.
'password' => 'HelloNSA', // Mantandory! Password of linux user.
//'uid' => 1100, // Optional. User ID of linux user. The ID must not exist!
//'gid' => 1100, // Optional. Primary group of the linux user. The group must exist! If this parameter is not present the Group name will be the User name and the Group ID will be the User ID or the first free ID.
'groups' => [ 'users' ], // Optional. Group membership of the linux user. It must be a simple indexed array what contains the groups in what the user will be member. The groups must exist.
//'nogroup' => true, // Optional. If true the Primary group will not be created. If 'gid' is present this parameter will be ineffective.
'comment' => 'test user', // Optional. Comment (display name) of linux user.
//'home' => '/home/test',// Optional. Absolute path of Home directory of linux user.
//'createhome' => true, // Optional. If false the Home directory will not be created.
//'shell' => '/bin/bash', // Optional. Absolute path of shell for linux user.
//'inactive' => 90, // Optional. The number of days after password expires that account is disabled.
//'expire' => 1640995199, // Optional. Date when account will be disabled. Format: timestamp.
//'system' => true, // Optional. If true create a system account. User ID will be under 1000. If 'uid' is present this parameter will be ineffective.
//'nonunique' => true , // Optional. If true allow to create users with duplicate (non-unique) User ID.
] ) )
print( "Something went wrong during Add user!" . PHP_EOL );
else
print( "'$user' user is created." . PHP_EOL );