---
title: Charmhub | Deploy Operator Libs Linux using Charmhub - The Open Operator Collection
description: Deploy the latest version of Operator Libs Linux on any cloud.
url: https://charmhub.io/operator-libs-linux/libraries/passwd
---

# Operator Libs Linux

[Jon Seager](https://charmhub.io/publisher/jnsgruk "View all packages from Jon Seager")

* [Jon Seager](https://charmhub.io/publisher/jnsgruk "View all packages from Jon Seager")

Platform:

22.04

20.04

stable 2

```
juju deploy operator-libs-linux
```

[Learn to deploy on juju >](https://juju.is/docs/juju/manage-applications)

[Toggle side navigation](https://charmhub.io/operator-libs-linux/libraries/passwd#drawer)

## charms.operator\_libs\_linux.v0.passwd

* [*Docstrings*Docstrings](https://charmhub.io/operator-libs-linux/libraries/passwd)
  [*Code*Source code](https://charmhub.io/operator-libs-linux/libraries/passwd/source-code)
* + Download

    Fetch library

    ```
    charmcraft fetch-lib charms.operator_libs_linux.v0.passwd
    ```

    [Download passwd.py](https://charmhub.io/operator-libs-linux/libraries/passwd/download)
  + *Last updated* 13 Feb 2026
  + *Revision* Library version 0.5

Legacy Charmhub-hosted passwd library, deprecated in favour of `charmlibs.passwd`.

WARNING: This library is deprecated and will no longer receive feature updates or bugfixes.
`charmlibs.passwd` version 1.0 is a bug-for-bug compatible migration of this library.
Add 'charmlibs-passwd~=1.0' to your charm's dependencies, and remove this Charmhub-hosted library.
Then replace `from charms.operator_libs_linux.v0 import passwd` with
`from charmlibs import passwd`.
Read more:

* https://documentation.ubuntu.com/charmlibs
* https://pypi.org/project/charmlibs-passwd

---

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
  )](https://charmhub.io/operator-libs-linux/libraries/passwd#user_exists)
* [def group\_exists(
  group
  )](https://charmhub.io/operator-libs-linux/libraries/passwd#group_exists)
* [def add\_user(
  username,
  password,
  shell,
  system\_user,
  primary\_group,
  secondary\_groups,
  uid,
  home\_dir,
  create\_home
  )](https://charmhub.io/operator-libs-linux/libraries/passwd#add_user)
* [def add\_group(
  group\_name,
  system\_group,
  gid
  )](https://charmhub.io/operator-libs-linux/libraries/passwd#add_group)
* [def add\_user\_to\_group(
  username,
  group
  )](https://charmhub.io/operator-libs-linux/libraries/passwd#add_user_to_group)
* [def remove\_user(
  user,
  remove\_home
  )](https://charmhub.io/operator-libs-linux/libraries/passwd#remove_user)
* [def remove\_group(
  group,
  force
  )](https://charmhub.io/operator-libs-linux/libraries/passwd#remove_group)

#### def user\_exists(user)

Check if a user exists.

Arguments

user

username or gid of user whose existence to check

#### def group\_exists(group)

Check if a group exists.

Arguments

group

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

Username to create

password

Password for user; if `None`, create a system user

shell

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`

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\_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`

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

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`

#### def remove\_user(     user,     remove\_home: bool )

Remove a user from the system.

Arguments

user

the username or uid of the user to remove

remove\_home

indicates whether the user's home directory should be removed

#### def remove\_group(     group,     force: bool )

Remove a user from the system.

Arguments

group

the name or gid of the group to remove

force

force group removal even if it's the primary group for a user
