Master Linux User & Permission Management: Commands, Options, and Best Practices
This guide explains how to view the current user, create and delete users and groups, modify passwords and account settings, and manage file permissions with chmod and ownership with chown, providing detailed command syntax and practical examples for Linux system administration.
Viewing the Current User
Use whoami to display the logged‑in username, or who am i for the user of the current pseudo‑terminal.
Common who Options
-a– display all available information -d – show dead processes -m – similar to
am i -q– show the number of logged‑in users and their names -u – display login information -r – show run level
Creating a New User
Simple creation:
adduser newnameDifference Between useradd and adduser
useraddonly creates the account; you must set a password afterwards with passwd newname. adduser creates the account, home directory, and prompts for a password, performing a full setup.
adduser Detailed Options
Usage:
adduser [options] login -b, --base-dir BASE_DIR– base directory for the new account’s home -c, --comment COMMENT – GECOS field -d, --home-dir HOME_DIR – home directory -D, --defaults – show or change default useradd configuration -e, --expiredate EXPIRE_DATE – account expiration date -f, --inactive INACTIVE – days after password inactivity before lock -g, --gid GROUP – primary group name or ID -G, --groups GROUPS – supplementary groups -h, --help – display help -k, --skel SKEL_DIR – skeleton directory -K, --key KEY=VALUE – override /etc/login.defs defaults -l, --no-log-init – do not add user to recent login databases -m, --create-home – create home directory -M, --no-create-home – do not create home directory -N, --no-user-group – do not create a group with the same name -o, --non-unique – allow duplicate UID -p, --password PASSWORD – encrypted password -r, --system – create a system account -R, --root CHROOT_DIR – chroot directory -s, --shell SHELL – login shell -u, --uid UID – user ID -U, --user-group – create a group with the same name as the user -Z, --selinux-user SEUSER – SELinux user mapping
Deleting a User
Use userdel:
userdel [options] username -f, --force– force removal even if the user is logged in -r, --remove – delete the user’s home directory and mail spool -R, --root CHROOT_DIR – operate inside a chroot -Z, --selinux-user – remove SELinux mappings
On systems without userdel, deluser –remove-home newname can be used to also delete the home directory.
Changing a User’s Password
passwd newnameModifying a User Account
Change primary group: usermod -g siatstudent newname Add the user to multiple groups: usermod -G friends,happy,funny newname Append a group without removing existing ones:
usermod -aG happy newnameViewing a User’s Groups
groups newnameGroup Management
Create a group:
groupadd newname -f, --force– succeed if the group already exists -g, --gid GID – specify GID -K, --key KEY=VALUE – override defaults -o, --non-unique – allow duplicate GID -p, --password PASSWORD – set encrypted password -r, --system – create a system group -R, --root CHROOT_DIR – chroot directory
Modify a group name: groupmod -n test2group testgroup Delete a group:
groupdel test2groupFile Ownership and Group Inspection
List files with owners and groups: ls -l Show current user’s groups: groups Show a specific user’s groups: groups testnewuser Display all groups:
cat /etc/groupchmod – Changing File Permissions
Basic syntax:
chmod [options]... MODE[,MODE]... FILE... -c, --changes– report only when a change is made -f, --silent, --quiet – suppress most error messages -v, --verbose – diagnostic output --no-preserve-root – do not treat '/' specially --preserve-root – fail when operating recursively on '/' --reference=RFILE – use RFILE’s mode as reference -R, --recursive – apply recursively --help – display help --version – display version
Permission symbols: u – user (owner) g – group o – others a – all + – add permission - – remove permission = – set exact permission
Examples:
chmod u+rx file.txt chmod g+r file.txt chmod o-r file.txt chmod g+r o-r file.txt chmod go-r file.txt chmod +x file.txt chmod u=rwx,g=r,o=- file.txt chmod -R 700 /home/newnamechown – Changing File Owner and Group
Basic usage: chown newname file.txt Change both owner and group: chown newname:friends file.txt Recursive change:
chown -R root /u -c, --changes– report only when a change is made -f, --silent, --quiet – suppress most error messages -v, --verbose – diagnostic output --dereference – affect the referent of symbolic links (default) -h, --no-dereference – affect symbolic links themselves --from=CURRENT_OWNER:CURRENT_GROUP – change only if current owner/group match -R, --recursive – operate recursively -H, -L, -P – control traversal of symbolic links when recursive --help – display help --version – display version
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
