Skip to content

Instantly share code, notes, and snippets.

@rferreiraperez
Last active July 30, 2024 08:58
Show Gist options
  • Save rferreiraperez/72ca502c29e58941bf10336934b01f80 to your computer and use it in GitHub Desktop.
Save rferreiraperez/72ca502c29e58941bf10336934b01f80 to your computer and use it in GitHub Desktop.

USERS AND GROUPS

User Management

Add a User

adduser <username>

Change User Password

passwd <username>

Change Root Password

passwd

Change Username

usermod -l <newUsername> <oldUsername>

Change User Home Directory

usermod -d /home/<newHomeDir> -m <username>

Disable a User

usermod -L <username>

Enable a User

usermod -U <username>

Delete a User

deluser <username>
deluser --remove-home <username>

Group Management

Add a User to a Group

usermod -aG <groupname> <username>

List Groups a User Belongs To

groups <username>

Create a New Group

addgroup <groupname>

Delete a Group

delgroup <groupname>

Switching Users and Root

Switch to Root User

sudo -i

Switch to Another User

su - <username>

User and Group Information

List All Users

cut -d: -f1 /etc/passwd

List All Groups

cut -d: -f1 /etc/group

Miscellaneous

Lock a User Account

passwd -l <username>

Unlock a User Account

passwd -u <username>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment