Linux decides who can do what with three pieces: user accounts, groups, and the read/write/execute permissions on every file. You manage them with useradd/adduser, usermod, and groupadd for accounts and chmod and chown for files. Get these right and each person and program has exactly the access it needs; get them wrong and you end up with locked-out users or files anyone can change.
This guide covers creating, changing, and removing users; giving admin rights with sudo; working with groups; reading and setting file permissions (including what numbers like 755 mean); special permission bits; ACLs; and a shared team folder you can build step by step. The commands are for Ubuntu and Debian, with notes where Red Hat family systems (Fedora, RHEL, Rocky, AlmaLinux) differ.
If you’re new to the command line, start with Linux Terminal: A Beginner’s Guide to Essential Commands. For setting up a whole server, see Linux Server: A Beginner’s Guide to Server Administration.
How Linux Users and Groups Work
Every account has a user name and a numeric user ID (UID). Linux itself works with the numbers; the names are for people.
- root (UID 0) is the superuser and can do anything. You rarely log in as root; you use
sudoinstead. - System users (usually UIDs below 1000) run services such as
www-datafor the web server orsshdfor SSH. Nobody logs in as them. - Regular users (UID 1000 and up) are people.
Each user has one primary group (on most distributions, a group with the same name as the user) and can belong to any number of supplementary groups, which is how you share access.
Accounts live in a few plain-text files:
| File | What it holds |
|---|---|
/etc/passwd | User name, UID, primary group ID, home folder, and login shell. Readable by everyone. |
/etc/shadow | Password hashes and expiry dates. Readable only by root. |
/etc/group | Group names, group IDs, and members. |
/etc/sudoers and /etc/sudoers.d/ | Who can run what with sudo. |
Don’t edit these files by hand. Use the commands below, which lock the files and check your input.
Check who you are and which groups you belong to:
whoami
id
groups
id prints something like uid=1000(jane) gid=1000(jane) groups=1000(jane),27(sudo).
Creating Users
Debian and Ubuntu have two commands. adduser is a friendly wrapper that asks for a password and creates the home folder:
sudo adduser jane
useradd is the low-level command available on every distribution. Give it the options you need, then set a password:
sudo useradd -m -s /bin/bash -c "Jane Doe" jane
sudo passwd jane
-mcreates the home folder (/home/jane).-s /bin/bashsets the login shell.-cadds a comment, usually the full name.
On Red Hat family systems adduser is just another name for useradd, so use the useradd form there.
To make a user change their password at first login:
sudo passwd --expire jane
Giving a User sudo (Admin) Rights
Add the user to the admin group. On Debian and Ubuntu it’s called sudo; on Red Hat family systems it’s wheel:
sudo usermod -aG sudo jane # Debian, Ubuntu
sudo usermod -aG wheel jane # Fedora, RHEL, Rocky, AlmaLinux
Always use -aG together. -G alone replaces all of the user’s supplementary groups with the one you list, quietly removing them from every other group. Group changes take effect at the user’s next login.
Limited sudo Rights
Not every admin task needs full root access. You can allow one specific command instead. Create a file in /etc/sudoers.d/ with visudo, which checks the syntax before saving (a broken sudoers file can lock everyone out of sudo):
sudo visudo -f /etc/sudoers.d/deploy
Add a line like this one, which lets the deploy user reload Nginx and nothing else:
deploy ALL=(root) /usr/bin/systemctl reload nginx
Check what a user is allowed to run:
sudo -l -U deploy
Changing Users
| Task | Command |
|---|---|
| Change the login shell | sudo usermod -s /bin/zsh jane |
| Rename a user | sudo usermod -l janedoe jane |
| Move the home folder | sudo usermod -d /home/janedoe -m janedoe |
| Set an account expiry date | sudo chage -E 2027-06-30 jane |
| See password and expiry info | sudo chage -l jane |
| Force a new password every 90 days | sudo chage -M 90 jane |
Locking and Removing Users
When someone leaves, lock the account first and delete it later, after you’ve saved any files you need.
sudo usermod --lock --expiredate 1 jane
--lock disables the password, and --expiredate 1 expires the whole account. Locking the password alone doesn’t stop SSH key logins, so set the expiry date too. To undo it:
sudo usermod --unlock --expiredate "" jane
To remove the user and their home folder:
sudo userdel -r jane
Before deleting, look for files the user owns outside their home folder:
sudo find / -xdev -user jane 2>/dev/null
Managing Groups
sudo groupadd developers # create a group
sudo usermod -aG developers jane # add a user
sudo gpasswd -d jane developers # remove a user
getent group developers # list members
sudo groupdel developers # delete a group
A user can pick up a new group without logging out by starting a shell with newgrp developers, but logging out and back in is simpler.
Understanding File Permissions
Run ls -l to see permissions:
ls -l report.txt
-rw-r----- 1 jane developers 2048 Dec 2 09:15 report.txt
Read the first column in four parts:
| Part | Example | Meaning |
|---|---|---|
| Type | - | - is a file, d a directory, l a symbolic link |
| Owner (user) | rw- | jane can read and write |
| Group | r-- | Members of developers can read |
| Others | --- | Everyone else gets nothing |
The letters mean slightly different things for files and directories:
| Permission | On a file | On a directory |
|---|---|---|
r (read) | Read the contents | List the names inside |
w (write) | Change the contents | Create, delete, and rename files inside (needs x too) |
x (execute) | Run it as a program | Enter it with cd and reach the files inside |
The directory rules surprise people: deleting a file depends on write permission on the directory, not on the file. And a directory without x can’t be entered even if you can read it.
Numeric (Octal) Permissions
Each permission has a number: read = 4, write = 2, execute = 1. Add them up for each of the three groups (owner, group, others):
| Number | Letters | Meaning |
|---|---|---|
| 7 | rwx | Read, write, execute |
| 6 | rw- | Read and write |
| 5 | r-x | Read and execute |
| 4 | r-- | Read only |
| 0 | --- | No access |
So 640 means owner rw- (6), group r-- (4), others --- (0). Common values:
| Value | Typical use |
|---|---|
644 | Regular files: owner edits, everyone reads |
755 | Directories and scripts: owner edits, everyone can enter or run |
600 | Private files such as SSH keys and .env files with secrets |
700 | Private directories such as ~/.ssh |
640 / 750 | Files and directories shared with one group only |
2775 | Shared team directories (see setgid below) |
Avoid 777. It lets every user and every program on the server change the file, which is almost never what you want.
Changing Permissions with chmod
Set permissions with numbers:
chmod 640 report.txt
chmod 755 deploy.sh
Or change them with letters: u (user/owner), g (group), o (others), a (all), plus + to add, - to remove, and = to set exactly:
chmod u+x deploy.sh # let the owner run it
chmod g+w report.txt # let the group edit it
chmod o-rwx report.txt # take everything away from others
chmod u=rw,g=r,o= report.txt # same as 640
chmod -R changes a whole folder tree, but it gives files and directories the same permissions, which is usually wrong. Use find to set them separately, for example for a website:
sudo find /var/www/example.com -type d -exec chmod 755 {} +
sudo find /var/www/example.com -type f -exec chmod 644 {} +
Changing Ownership with chown and chgrp
sudo chown jane report.txt # change the owner
sudo chown jane:developers report.txt # change the owner and group
sudo chgrp developers report.txt # change only the group
sudo chown -R www-data:www-data /var/www/example.com # a whole folder
Only root can give a file to another user, so chown usually needs sudo.
Default Permissions: umask
New files don’t start at 777. The umask removes permissions from the default. Check yours:
umask
With the common umask 0022, new files get 644 and new directories 755. With 0002, they get 664 and 775, which suits shared group folders. Set it for a session with umask 0027, or per user in ~/.bashrc.
Special Permissions: setuid, setgid, and Sticky Bit
A fourth digit in front of the usual three adds a special permission:
| Bit | Number | On a file | On a directory | Example |
|---|---|---|---|---|
| setuid | 4 | Runs as the file’s owner | (no effect) | /usr/bin/passwd shows -rwsr-xr-x |
| setgid | 2 | Runs with the file’s group | New files inherit the directory’s group | Shared team folders |
| sticky | 1 | (no effect) | Only a file’s owner can delete it | /tmp shows drwxrwxrwt |
setuid programs run with root’s power, so attackers look for unusual ones. List them now and then:
sudo find / -xdev -type f -perm -4000 2>/dev/null
Access Control Lists (ACLs)
Standard permissions give you one owner and one group. When you need more, such as one extra user who should read a folder, use an ACL. Install the tools first if needed (sudo apt install acl):
sudo setfacl -m u:alex:rx /srv/reports # give alex read access
sudo setfacl -d -m u:alex:rx /srv/reports # and to new files created later
getfacl /srv/reports # show the ACL
sudo setfacl -x u:alex /srv/reports # remove alex's entry
A + at the end of the permissions in ls -l (for example drwxr-x---+) means the file has an ACL.
Example: A Shared Folder for a Team
Here’s how the pieces fit together. Alice and Bob should both edit files in /srv/projects/website, and nobody else should see them.
# 1. Create the group and add both users
sudo groupadd webteam
sudo usermod -aG webteam alice
sudo usermod -aG webteam bob
# 2. Create the folder, give it to the group, and set setgid
sudo mkdir -p /srv/projects/website
sudo chown root:webteam /srv/projects/website
sudo chmod 2770 /srv/projects/website
# 3. Make new files group-writable whatever each user's umask is
sudo setfacl -d -m g:webteam:rwx /srv/projects/website
The setgid bit (the 2) makes every new file belong to webteam instead of the creator’s own group, and the default ACL makes new files group-writable. Alice and Bob need to log out and back in to pick up the new group.
Auditing Users and Permissions
A quick review every month or so catches most problems:
# Who has admin rights?
getent group sudo wheel
# Which accounts can log in? (they have a real shell)
grep -vE 'nologin|false' /etc/passwd
# Recent logins
last -n 20
# Recent sudo use
sudo journalctl _COMM=sudo --since "7 days ago"
# World-writable files (anyone can change them)
sudo find / -xdev -type f -perm -0002 2>/dev/null
Remove accounts and admin rights nobody uses anymore. This is the least privilege principle: every user and program gets only the access it needs.
Common Mistakes
usermod -Gwithout-a, which removes the user from every other group, sometimes includingsudo.chmod -R 777to “fix” a permission error. Find which user needs access and grant only that.- Running services as root when they could run as their own system user.
- Shared accounts (one
adminlogin for the whole team). Give everyone their own account so logs show who did what. - Wrong permissions on SSH files. SSH refuses keys if
~/.sshisn’t700orauthorized_keysisn’t600. - Forgetting to log out after a group change, then wondering why it didn’t work.
Conclusion
User and permission management comes down to a few habits: one account per person, sudo instead of root, groups for shared access, and the smallest permissions that work. Learn to read ls -l and the numbers behind 644 and 755, use find rather than chmod -R, and reach for setgid and ACLs when a team needs to share files. These same skills protect a server, which is the topic of Linux Server Security: 10 Best Practices to Protect Your Server.
Frequently Asked Questions
What’s the difference between adduser and useradd?
useradd is the standard low-level command on every Linux distribution. On Debian and Ubuntu, adduser is a friendlier script that asks questions and creates the home folder. On Red Hat family systems, adduser is just a link to useradd.
What does chmod 755 mean?
The owner can read, write, and execute (7), and the group and everyone else can read and execute (5). It’s the usual setting for directories and scripts.
How do I see all users on a Linux system?
Run getent passwd or cat /etc/passwd. To list only regular users, filter by UID: awk -F: '$3 >= 1000 && $3 < 65534 {print $1}' /etc/passwd.
Why do I get “Permission denied” even with chmod 777?
Check the directories above the file: every directory in the path needs x permission for you. Also check for SELinux or AppArmor rules and for file systems mounted read-only or with noexec.
Should I log in as root?
No. Use a regular account and sudo for admin tasks. sudo logs every command, asks for confirmation, and keeps a typo from becoming a disaster as easily.
Related Reading
Want to keep learning? These related guides pair well with this post:
