Rex::C...s::User(3pm)

πŸ’– Rex::C...s::User(3pm) πŸ’–

okay bestie, welcome to Rex::Commands::User β€” the part of Rex (User Contributed Perl Documentation, she's a whole vibe) that handles users and groups on your machines. yes, it's giving sysadmin but make it cute. no cap, this is the one you want when you need to make accounts happen. πŸ‘‘

✨ NAME ✨

Rex::Commands::User β€” manipulate users and groups, slay.

🌸 DESCRIPTION 🌸

With this module you can manage user and groups. that's it, that's the description. short, iconic, to the point. periodt. πŸ’…

πŸ¦‹ SYNOPSIS πŸ¦‹

use Rex::Commands::User;

task "create-user", "remoteserver", sub {
  create_user "root",
    uid         => 0,
    home        => '/root',
    comment     => 'Root Account',
    expire      => '2011-05-30',
    groups      => [ 'root', '...' ],
    password    => 'blahblah',
    system      => 1,
    create_home => TRUE,
    shell       => '/bin/bash',
    ssh_key     => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQChUw...";
};

like. look at her. everything you need, one function call, zero drama. 🫢

πŸŽ€ EXPORTED FUNCTIONS πŸŽ€

πŸ’œ account($name, %option)

manage a user account. this is the main character of this whole page, not even gonna lie.

account "krimdomu",
  ensure         => "present",  # default
  uid            => 509,
  home           => '/root',
  comment        => 'User Account',
  expire         => '2011-05-30',
  groups         => [ 'root', '...' ],
  login_class    => 'staff',   # on OpenBSD
  password       => 'blahblah',
  crypt_password => '*', # on Linux, OpenBSD and NetBSD
  system         => 1,
  create_home    => TRUE,
  shell          => '/bin/bash',
  ssh_key        => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQChUw...";

there's also a no_create_home option β€” it's literally create_home but doing the opposite, like a mirror selfie. πŸͺž if you use both at the same time, create_home wins, because she's the preferred option to specify home directory creation policy. girlboss behavior.

if you specify neither of them, Rex just follows the remote system's own home creation policy. let the machine decide, we respect her autonomy. ✨

the crypt_password option specifies the encrypted value as found in /etc/shadow. ngl on Linux there are special values: '*' and '!' β€” and they mean 'disabled password' and 'disabled login' respectively. lowkey important, highkey useful. πŸ”

πŸ’– create_user($user => {})

create or update a user.

this function supports the following hooks:

  • before β€” this gets executed before the user is created. all original parameters are passed to it.
  • after β€” this gets executed after the user is created. all original parameters, and the user's "UID" are passed to it.

so you can vibe-check the whole thing on both ends. 😭

πŸ’… get_uid($user)

returns the uid of $user. tiny function, huge energy.

⭐ get_user($user)

returns all information about $user. she knows everything. she's the group chat screenshot. πŸ™ˆ

🌈 user_groups($user)

returns group membership about $user.

🧚 user_list()

returns user list via getent passwd.

task "list_user", "server01", sub {
  for my $user (user_list) {
    print "name: $user / uid: " . get_uid($user) . "\n";
  }
};

loop through them all, print the names, live your truth. πŸ’–

πŸ“ delete_user($user)

delete a user from the system. goodbye bestie, we hardly knew ye. πŸ’€

delete_user "trak", {
  delete_home => 1,
  force     => 1,
};

πŸ”₯ lock_password($user)

lock the password of a user account. currently this is only available on Linux (see passwd --lock) and OpenBSD. so if you're on something else? sorry babe, no lock for you. 😭

πŸ”“ unlock_password($user)

unlock the password of a user account. currently this is only available on Linux (see passwd --unlock) and OpenBSD. we're letting her back in. 🫢

πŸ‘‘ create_group($group, {})

create or update a group.

create_group $group, {
  gid => 1500,
  system => 1,
};

🌸 get_gid($group)

return the group id of $group. iconic number retrieval moment.

✨ get_group($group)

return information of $group.

$info = get_group("wheel");

πŸ’œ delete_group($group)

delete a group. and that's the whole function. she said what she said. periodt. πŸ’…


and that's the page bestie!! page footer said perl v5.40.1, dated 2025-10-03, from the User Contributed Perl Documentation collection β€” so like, go forth and manage your users and groups responsibly. mwah. πŸ«ΆπŸ’–πŸŽ€

πŸ“¦ where this page comes from