diff --git a/knowledge base/useradd.md b/knowledge base/useradd.md new file mode 100644 index 0000000..6fe84c7 --- /dev/null +++ b/knowledge base/useradd.md @@ -0,0 +1,39 @@ +# Useradd + +Create a new user. + +## TL;DR + +```shell +# Create a new user. +sudo useradd username +sudo useradd -p encryptedPassword username + +# Create a new user with the specified user ID. +sudo useradd --uid id username + +# Create a new user with the specified expiration date. +sudo useradd -e 2022-10-10 username + +# Create a new user with the specified shell. +sudo useradd --shell path/to/shell username + +# Create a new user belonging to additional groups. +sudo useradd --groups group1,group2,... username + +# Create a new user with or without its default home directory. +sudo useradd --create-home username +sudo useradd --no-create-home username + +# Create a new user with the home directory filled by template directory files. +sudo useradd --skel path/to/template_directory --create-home username + +# Create a new system user without the home directory. +sudo useradd --system username +``` + +## Sources + +- [cheat.sh] + +[cheat.sh]: cheat.sh/useradd diff --git a/knowledge base/userdel.md b/knowledge base/userdel.md new file mode 100644 index 0000000..c7839a8 --- /dev/null +++ b/knowledge base/userdel.md @@ -0,0 +1,22 @@ +# Useradd + +Delete a user account and its related files. + +## TL;DR + +```shell +# Remove a user. +sudo userdel username + +# Remove a user in other root directory. +sudo userdel --root path/to/other/root username + +# Remove a user along with the home directory and mail spool. +sudo userdel --remove username +``` + +## Sources + +- [cheat.sh] + +[cheat.sh]: cheat.sh/userdel diff --git a/knowledge base/usermod.md b/knowledge base/usermod.md index 62da5d3..9f2aca2 100644 --- a/knowledge base/usermod.md +++ b/knowledge base/usermod.md @@ -3,6 +3,36 @@ ## TL;DR ```shell -# Add users to a group. -sudo usermod --append --groups boinc user +# Change a user's primary group. +sudo usermod -g docker bob + +# Add/remove a user to/from supplementary groups. +sudo usermod -aG wheel carly +sudo usermod --append --groups kvm,video,audio alice +sudo usermod -rG sudo,admin eve + +# Change a user's login name +sudo usermod --login to-stephen from-micha + +# Change a user's ID. +sudo usermod --uid 1001 hugo + +# Change a user's shell. +sudo usermod --shell /usr/bin/zsh rick + +# Change a user's password. +sudo usermod -p encryptedPassword john + +# Lock/unlock a user. +sudo usermod -L damian +sudo usermod -U luke + +# Change a user's home directory. +sudo usermod --move-home --home path/to/new_home lonny ``` + +## Sources + +- [cheat.sh] + +[cheat.sh]: cheat.sh/usermod