Crate change_user_run

Source
Expand description

ยงChange-user-run ๐Ÿ”„๐Ÿ–ฅ๏ธ๐Ÿƒโ€โžก๏ธ

A simple Rust library to aide with the creation of users and running commands as users on Linux systems.

If you have ever had the need to conveniently run commands as other users (e.g. in containerized tests), or to create new users on a Linux system, this is for you!

ยงDocumentation

Refer to https://docs.rs/change_user_run/latest/change_user_run/ for released versions of the crate.

ยงExamples

Create a set of users

use change_user_run::create_users;

// Create a single user in the default location with the default shell.
create_users(&["testuser1", "testuser2"], None, None)?;

Run a command using a separate user

use change_user_run::run_command_as_user;

// Run `whoami` as the user `testuser1`.
run_command_as_user("whoami", &[], None, &[], None, "testuser1");

ยงContributing

Please refer to the contributing guidelines to learn how to contribute to this project.

ยงReleases

Releases are created by the developers of this project.

[OpenPGP certificates] with the following [OpenPGP fingerprints] can be used to verify signed tags:

Some of the above are part of archlinux-keyring and certified by at least three main signing keys of the distribution. All certificate are cross-signed and can be retrieved from OpenPGP keyservers.

ยงLicense

This project can be used under the terms of the Apache-2.0 or MIT. Contributions to this project, unless noted otherwise, are automatically licensed under the terms of both of those licenses.

Enumsยง

Error
An error that may occur when creating users or running a command as different user.

Constantsยง

DEFAULT_SHELL
The default shell used for new users (/usr/bin/bash).

Functionsยง

create_users
Creates a set of users using useradd and unlocks them using usermod.
get_command
Returns the path to a command.
run_command_as_user
Runs command with command_args and optional command_input as user.