passwd¶
The charmlibs.passwd package.
- add_group(group_name: str, system_group: bool = False, gid: int | None = None)¶
Add a group to the system.
Will log but otherwise succeed if the group already exists.
- Parameters:
group_name – group to create
system_group – Create system group
gid – GID for user being created
- Returns:
The group’s password database entry struct, as returned by grp.getgrnam
- add_user(
- username: str,
- password: str | None = None,
- shell: str = '/bin/bash',
- system_user: bool = False,
- primary_group: str | None = None,
- secondary_groups: list[str] | None = None,
- uid: int | None = None,
- home_dir: str | None = None,
- create_home: bool = True,
Add a user to the system.
Will log but otherwise succeed if the user already exists.
- Parameters:
username – Username to create
password – Password for user; if
None, create a system usershell – The default shell for the user
system_user – Whether to create a login or system user
primary_group – Primary group for user; defaults to username
secondary_groups – Optional list of additional groups
uid – UID for user being created
home_dir – Home directory for user
create_home – Force home directory creation
- Returns:
The password database entry struct, as returned by pwd.getpwnam
- add_user_to_group(username: str, group: str)¶
Add a user to a group.
- Parameters:
username – user to add to specified group
group – name of group to add user to
- Returns:
The group’s password database entry struct, as returned by grp.getgrnam
- group_exists(group: str | int) struct_group | None¶
Check if a group exists.
- Parameters:
group – username or gid of user whose existence to check
- Raises:
TypeError – where neither a string or int is passed as the first argument
- remove_group(group: str | int, force: bool = False) bool¶
Remove a user from the system.
- Parameters:
group – the name or gid of the group to remove
force – force group removal even if it’s the primary group for a user