Skip to content

About

Bash CLI to create, update, and delete Linux users on Debian/Kali

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

25 Commits

Folders and files

Repository files navigation

UserManager

License: MIT Shell Platform

Command-line helper to create, modify, and delete Linux users and groups on Debian and Kali. It is meant for helpdesk and junior penetration-testing lab work on machines you administer.

Contents

Features

  • Create a user, with or without a new group
  • Add an existing user to a new or existing group
  • Set the login shell (bash, zsh, or another name under /usr/bin)
  • Delete a user and that user's home directory, only after a y confirmation
  • Refuse to run unless you are root
  • Print the matching /etc/passwd and /etc/group lines so you can check the result

Authorized use

Use this only on systems you are authorized to administer. -Ud removes the account and /home/<username> after you answer y. There is no undo.

Prerequisites

  • Debian or Kali Linux (adduser / addgroup are Debian-family wrappers).
  • Root privileges (sudo).
  • adduser and addgroup on PATH.
  • git, only for the installer below.

Installation

curl -O https://raw.githubusercontent.com/avitwil/UserManager/main/user_manager
chmod +x user_manager
sudo ./user_manager

The installer clones this repository (or updates a clone already in the current directory), copies userman and userman.help to /usr/bin, and removes the temporary clone. It must be run as root.

To try the command from a clone without installing it:

git clone https://github.com/avitwil/UserManager.git
cd UserManager
sudo ./userman --help

userman --help reads /usr/bin/userman.help when that file is installed, and the copy next to the script otherwise.

How it works

userman is a short Bash wrapper around the Debian account tools.

  1. It checks the effective user id and exits if you are not root.
  2. It accepts one account action (-u, -U, or -Ud), an optional group (-g for a new group, -G for an existing one), an optional shell (-s), or --help.
  3. A new account goes through adduser, which prompts for a password and the usual name and phone fields. The password is not echoed. -g creates the group with addgroup first.
  4. -s bash runs usermod -s /usr/bin/bash. Pass the program name, not a full path.
  5. Group changes use usermod -aG, which adds the group and leaves the user's other groups in place.
  6. -Ud asks [y/n]. y runs userdel and then deletes that user's home directory. Any other answer stops and leaves the account as it is.
  7. After a create or modify, the script prints the matching lines from /etc/passwd and /etc/group.

Usage examples

The sessions below were run locally against the fictional account acmehelp and group acme-staff. Numeric ids in /etc/passwd and /etc/group depend on the machine. On Debian, adduser also adds the account to the users group.

Help

sudo userman --help

userman --help

Root check

Without root the script stops before it reads any account flags:

userman --help
This script must be run as root (use sudo).

userman refuses to run without root

Create a user and a new group

sudo userman -u acmehelp -g acme-staff

adduser asks for a password (hidden) and for full name, room, and phone. Press Enter to accept a blank field, then confirm with Y.

Creating acmehelp and the acme-staff group

The script then prints the new records. This is the result from the capture above:

--------------------------------------------------------
acmehelp in /etc/passwd file
--------------------------------------------------------
acmehelp:x:1002:1002:ACME Helpdesk,,,:/home/acmehelp:/bin/bash
--------------------------------------------------------

--------------------------------------------------------
acmehelp in /etc/group file
--------------------------------------------------------
users:x:100:acmehelp
acme-staff:x:1001:acmehelp
acmehelp:x:1002:
--------------------------------------------------------

Change the login shell

sudo userman -U acmehelp -s bash
--------------------------------------------------------
acmehelp in /etc/passwd file
--------------------------------------------------------
acmehelp:x:1002:1002:ACME Helpdesk,,,:/home/acmehelp:/usr/bin/bash
--------------------------------------------------------

Setting the acmehelp shell to bash

Delete the account

sudo userman -Ud acmehelp
Are you sure you want to delete acmehelp and all of their files? [y/n]: y
User acmehelp and all of their files have been deleted

Deleting acmehelp after confirmation

An answer other than y exits without deleting anything.

Other common forms

userman -u USER                         create a new user
userman -u USER -s SHELL                create a user and set their shell
userman -U USER -s SHELL                change an existing user's shell
userman -u USER -g GROUP                create a user and a new group
userman -u USER -G GROUP                create a user in an existing group
userman -U USER -g GROUP                add an existing user to a new group
userman -U USER -G GROUP                add an existing user to an existing group
userman -Ud USER                        delete a user and their home directory
userman --help                          show help

Options

Option Description
-u Create a new user
-U Select an existing user to modify
-Ud Delete an existing user and their home directory
-g Create a new group and add the user to it
-G Add the user to an existing group
-s Set the login shell; use with -u or -U
--help Show help

Run it as root: sudo userman ....

What's included

  • userman — create, update, and delete users and groups, and set login shells. Installed to /usr/bin/userman.
  • userman.help — help text for userman --help. Installed to /usr/bin/userman.help.
  • user_manager — installer. Clones this repository, copies the two files into /usr/bin, and removes the temporary clone.
  • docs/screenshots/ — terminal captures used in this README.

License

MIT — see LICENSE.

Made by Avi Twil.

About

Bash CLI to create, update, and delete Linux users on Debian/Kali

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages