Operator Libs Linux
- Jon Seager
Channel | Revision | Published | Runs on |
---|---|---|---|
latest/stable | 2 | 09 Mar 2023 | |
latest/stable | 1 | 28 Oct 2021 |
juju deploy operator-libs-linux
Deploy universal operators easily with Juju, the Universal Operator Lifecycle Manager.
Platform:
charms.operator_libs_linux.v0.passwd
-
- Last updated 23 Feb 2023
- Revision Library version 0.4
Simple library for managing Linux users and groups.
The passwd
module provides convenience methods and abstractions around users and groups on a
Linux system, in order to make adding and managing users and groups easy.
Example of adding a user named 'test':
import passwd
passwd.add_group(name='special_group')
passwd.add_user(username='test', secondary_groups=['sudo'])
if passwd.user_exists('some_user'):
do_stuff()
Index
def user_exists(user)
Check if a user exists.
Arguments
username or gid of user whose existence to check
def group_exists(group)
Check if a group exists.
Arguments
username or gid of user whose existence to check
def
add_user(
username: str,
password,
shell: str,
system_user: bool,
primary_group: str,
secondary_groups,
uid: int,
home_dir: str,
create_home: bool
)
Add a user to the system.
Arguments
Username to create
Password for user; if None
, create a system user
The default shell for the user
Whether to create a login or system user
Primary group for user; defaults to username
Optional list of additional groups
UID for user being created
Home directory for user
Force home directory creation
Returns
The password database entry struct, as returned by pwd.getpwnam
Description
Will log but otherwise succeed if the user already exists.
def
add_group(
group_name: str,
system_group: bool,
gid: int
)
Add a group to the system.
Arguments
group to create
Create system group
GID for user being created
Returns
The group's password database entry struct, as returned by grp.getgrnam
Description
Will log but otherwise succeed if the group already exists.
def
add_user_to_group(
username: str,
group: str
)
Add a user to a group.
Arguments
user to add to specified group
name of group to add user to
Returns
The group's password database entry struct, as returned by grp.getgrnam
def
remove_user(
user,
remove_home: bool
)
Remove a user from the system.
Arguments
the username or uid of the user to remove
indicates whether the user's home directory should be removed
def
remove_group(
group,
force: bool
)
Remove a user from the system.
Arguments
the name or gid of the group to remove
force group removal even if it's the primary group for a user