pub fn create_users(
users: &[&str],
home_base_dir: Option<&Path>,
shell: Option<&Path>,
) -> Result<(), Error>
Expand description
Creates a set of users using useradd and unlocks them using usermod.
Optionally, the base directory for the home directory of all users and the shell can be
provided. By default DEFAULT_SHELL
is used as the user’s shell.
§Note
User creation is a privileged action which requires calling this function as root.
§Errors
Returns an error if
- the useradd or usermod commands cannot be found,
- the useradd command cannot be executed,
- a user and/or its home cannot be created,
- the usermod command cannot be executed,
- or unlocking a created user fails.
§Examples
use std::path::Path;
use change_user_run::create_users;
// Create a single user in the default location with the default shell.
create_users(&["testuser"], None, None)?;
// Create a set of users, with home directories under a custom directory, using a custom shell.
create_users(
&["testuser"],
Some(&Path::new("/var/lib/custom")),
Some(&Path::new("/usr/bin/fish")),
)?;