Linux
Users & Groups
Create users, manage groups, and grant sudo access.
By EZ4Code Team
usergroupsudo
Code
# Create user with home directory and shell
sudo useradd -m -s /bin/bash alice
sudo passwd alice
# Modify user
sudo usermod -aG docker,sudo alice
sudo usermod -L alice # lock password
sudo usermod -U alice # unlock password
# Groups
sudo groupadd developers
sudo gpasswd -d alice developers
getent group developers
# Sudo access
echo "alice ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart nginx" \
| sudo tee /etc/sudoers.d/alice
sudo visudo -c # validate sudoers
# Switching users
su - alice
sudo -iu alice # login shell as alice
id alice # show uid, gid, groupsExplanation
useradd -m creates a user with a home directory, and -aG appends them to supplementary groups without removing existing memberships. Always edit sudoers via visudo or /etc/sudoers.d snippets to avoid locking yourself out. usermod -L locks an account by prefixing the password hash, denying password logins.
More Linux Snippets
File Operations
Copy, move, link, and search files efficiently.
Permissions & Ownership
Manage read/write/execute bits with chmod and chown.
Process Management
List, signal, and monitor running processes.
Networking
Inspect interfaces, ports, connections, and DNS.
Package Management
Install, update, and search packages on Debian and RHEL.
Text Processing
Filter, transform, and summarize text streams.