Learn › Linux

Linux Users, Permissions and sudo Explained for Windows Admins

How Linux users and groups work, how to read rwx permissions, change them with chmod and chown, and use sudo safely instead of logging in as root.

Beginner 10 min read
By Gopinath Karthikeyan

Linux permissions look cryptic (-rwxr-x---) but they’re simpler than NTFS ACLs. Once you can read them, a large share of “permission denied” problems take seconds to fix.

Users and groups

Every file belongs to one user (owner) and one group. Every process runs as a user.

whoami                 # your user
id                     # your user ID, groups
getent passwd jenkins  # details of a user
getent group docker    # members of a group

Service accounts like jenkins, www-data or prometheus are normal users that apps run as – just like Windows service accounts.

Reading permissions

ls -l
-rwxr-x---  1 alice  devops  2048 Nov 29 10:00 deploy.sh
drwxr-xr-x  2 alice  devops  4096 Nov 29 10:00 scripts

The first column breaks down as:

-   rwx    r-x    ---
│   │      │      └─ others (everyone else)
│   │      └──────── group (devops)
│   └─────────────── owner (alice)
└─────────────────── type: - file, d directory, l link
Letter On a file On a directory
r read the contents list the names inside
w change the contents create, delete, rename files inside
x run it as a program enter it (cd) and access files inside

So deploy.sh above: alice can read, write and run it; group devops can read and run; nobody else can touch it.

Numbers: 755, 644, 600

Each set is a sum: r = 4, w = 2, x = 1.

Number Letters Typical use
755 rwxr-xr-x Scripts and folders everyone may use
644 rw-r–r– Normal files and configs
750 rwxr-x— Scripts only owner and group may use
600 rw——- Secrets: private keys, password files

Changing permissions and owners

chmod 755 deploy.sh          # set exact permissions
chmod +x deploy.sh           # add execute for everyone
chmod g-w config.yml         # remove write from group
chmod 600 ~/.ssh/id_ed25519  # private key: owner only

sudo chown jenkins:jenkins /var/lib/myapp        # change owner and group
sudo chown -R jenkins:jenkins /var/lib/myapp     # recursively

Never “fix” a problem with chmod -R 777. It gives everyone full rights and creates a security hole that’s hard to undo.

Managing users

sudo adduser alice                 # create a user (Ubuntu/Debian, interactive)
sudo usermod -aG devops alice      # add to a group (-a = append, don't forget it!)
sudo passwd alice                  # set a password
sudo deluser alice                 # remove

A user has to log out and back in to pick up new group membership.

root and sudo

root is the all-powerful account, like a local Administrator with no limits. Day to day you log in as yourself and use sudo for the few commands that need root:

sudo systemctl restart nginx
sudo -i            # a root shell – use rarely, and exit as soon as you're done

Who may use sudo is set in /etc/sudoers – edit it only with sudo visudo, which checks your syntax before saving (a broken sudoers file can lock everyone out of sudo). On Ubuntu, members of the sudo group have full sudo rights.

Troubleshooting “Permission denied”

  1. Who is running the command? (whoami – or which user does the service run as?)
  2. ls -l the file and every parent directory – a directory without x blocks access to everything inside.
  3. Does the user’s group own the file? (id user)
  4. Did you just add the user to a group? They need a new login session.

FAQ

Is there anything like NTFS ACLs? Yes – setfacl and getfacl add extra user/group rules. Most servers manage fine with owner/group/other, though.

What’s next

Next: Packages and services with apt and systemd.

LinuxPermissionsSecurityBeginner

Gopinath Karthikeyan

Gopinath Karthikeyan – Windows Site Reliability Engineer with about 12 years in enterprise Windows Server infrastructure, and founder of WinOps Academy. YouTube · LinkedIn

More in Linux