User

class rmote.tools.user.Result(name, uid, gid, home, shell, changed)[source]

Bases: object

changed: bool
gid: int
home: str
name: str
shell: str
uid: int
class rmote.tools.user.GroupResult(name, gid, changed)[source]

Bases: object

changed: bool
gid: int
name: str
class rmote.tools.user.User[source]

Bases: Tool

Manage users, groups, SSH keys, and sudoers on the remote host. Requires root.

static absent(name, *, remove_home=False)[source]

Ensure a user does not exist. Returns True if user was removed.

Parameters:
  • name (Text) – Username

  • remove_home (bool) – Also remove the user’s home directory

Return type:

bool

static authorized_key(name, key, *, exclusive=False)[source]

Ensure an SSH public key is present in ~/.ssh/authorized_keys.

Parameters:
  • name (Text) – Username

  • key (Text) – SSH public key string

  • exclusive (bool) – If True, replace the entire authorized_keys with only this key

Return type:

bool

Returns:

True if file was changed.

static group_absent(name)[source]

Ensure a group does not exist. Returns True if group was removed.

Return type:

bool

static group_present(name, *, gid=None, system=False)[source]

Ensure a group exists. Idempotent.

Return type:

GroupResult

static present(name, *, uid=None, gid=None, comment='', home=None, shell='/bin/bash', groups=None, append_groups=True, system=False, create_home=True)[source]

Ensure a user exists with the given attributes. Idempotent.

Parameters:
  • name (Text) – Username

  • uid (int | None) – Numeric UID (optional)

  • gid (int | None) – Primary GID or group name (optional)

  • comment (Text) – GECOS field

  • home (Text | None) – Home directory path (default: /home/<name>)

  • shell (Text) – Login shell

  • groups (list[Text] | None) – Supplementary groups

  • append_groups (bool) – If True, add to groups without removing existing ones

  • system (bool) – Create as system user (no home, lower UID range)

  • create_home (bool) – Create home directory if it does not exist

Return type:

Result

static sudoer(name, *, nopasswd=True, absent=False)[source]

Manage a sudoers drop-in for a user in /etc/sudoers.d/.

Parameters:
  • name (Text) – Username

  • nopasswd (bool) – Grant passwordless sudo

  • absent (bool) – Remove the sudoers entry instead

Return type:

bool

Returns:

True if file was changed.