User¶
Manage accounts, groups, authorized keys, and sudoers as root.
sudoer grants all commands as any user; it does not run visudo.
See Quickstart for account setup and sudo validation.
- class rmote.tools.user.User[source]¶
Bases:
ToolManage users, groups, SSH keys, and sudoers on the remote host. Requires root.
Creating or removing a user or a group runs the shadow utilities (
useraddand its family), and a target without them refuses with NotImplementedError.sudoerandauthorized_keyonly write files, so they work on any POSIX target.Create a group and user in a disposable Debian container, then remove them:
>>> remote = getfixture("debian_tool") >>> group = remote(User.group_present, "deployers") >>> group.changed True >>> remote(User.group_present, "deployers").changed False >>> remote(User.present, "deploy", gid=group.gid, create_home=False).changed True >>> remote(User.present, "deploy", gid=group.gid, create_home=False).changed False >>> remote(User.absent, "deploy") True >>> remote(User.absent, "deploy") False >>> remote(User.group_absent, "deployers") True
- async static absent(name, *, remove_home=False)[source]¶
Ensure a user does not exist. Returns True if user was removed.
- static authorized_key(name, key, *, exclusive=False)[source]¶
Ensure an SSH public key is present in ~/.ssh/authorized_keys.
- async static group_absent(name)[source]¶
Ensure a group does not exist. Returns True if group was removed.
- Return type:
- async static group_present(name, *, gid=None, system=False)[source]¶
Ensure a group exists. Idempotent.
- Return type:
- async 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) – Usernameuid (
getint|None) – Numeric UID (optional)gid (
getint|None) – Numeric primary GID (optional)comment (
Text) – GECOS fieldhome (
Text|None) – Home directory path (default: /home/<name>)shell (
Text) – Login shellappend_groups (
bool) – If True, add to groups without removing existing onessystem (
bool) – Create as system user (no home, lower UID range)create_home (
bool) – Create home directory if it does not exist
- Return type: