User and Permission Management for Raspberry Pi¶
A permission error tells you that an account cannot perform an operation on a particular resource. Learn to identify the account, owner and access rules before changing permissions or running a program as root.
Before you start¶
You need a working Raspberry Pi OS login and the terminal basics. Run commands on the Pi, except the SSH-key section, which explicitly runs on your client computer.
The main exercise creates a private folder in your home. It does not change other users, system directories, login policy or device permissions. Administrative changes later in the article are optional, not prerequisites.
1. Identify your account and groups¶
id shows your numeric user ID, primary group and supplementary groups. getent queries the account database. Root has UID 0; do not infer that every account with a large UID is a human or that every service account is below 1000.
Current Raspberry Pi OS creates the account you choose during installation. There is no universal default pi account or password.
2. Read a file's owner and mode¶
Create a fresh private exercise:
A listing might show:
The names, size and date will differ. The first character marks the file type; the next nine characters are three sets of permissions: owner, group, others.
| Symbol | Regular file | Directory |
|---|---|---|
r |
Read contents | List entry names |
w |
Modify contents | Create/remove/rename entries, normally requiring directory execute permission too |
x |
Execute as a program | Traverse the directory to reach an entry |
Deleting a file normally depends on the parent directory's permissions, not just the file's write permission. ACLs and special directory rules can add further constraints.
3. Make the exercise file private¶
Check: the numeric mode is 600 and you can still read the file as its owner. The private directory created by mktemp also restricts other users from traversing it.
Numeric permissions add read=4, write=2, execute=1 for each class. Thus 600 gives the owner read/write and gives no mode-bit access to group/others. 700 is useful for a private directory. 644 lets others read a regular file if they can reach it.
Permissions do not encrypt contents or prevent root from accessing them. Do not claim this exercise protects secrets from every possible attacker.
4. See why directories matter¶
Check: the directory mode is drwx------. You can traverse it because you own it. Making a file readable does not make every parent directory traversable.
Use narrow changes to named files. Avoid chmod 777, recursive ownership changes or changing /tmp as a repair for an application error. If a system-owned file is inaccessible, that may be intentional.
5. Understand groups and hardware access¶
Groups can grant access to devices without giving a program full administrator privileges. Check the actual device and your current session:
On the available Pi 4B, GPIO character devices belong to root:gpio and the existing account belongs to gpio. This is observed configuration, not a promise that every image uses identical rules.
When intentionally giving your own account GPIO access on Raspberry Pi OS, an administrator can use:
Only use this if the group exists and the device ownership confirms it is relevant. -aG appends a supplementary group; using -G without -a can remove existing memberships, including administrator access.
Start a new login session, then use id to verify the active memberships. Keeping an old SSH session open does not refresh its groups. Do not chmod device files to world-writable: udev may recreate them and the access is broader than intended.
Group membership is not always low risk. For example, access to a privileged Docker daemon is effectively root-equivalent. Add accounts only to groups they actually need.
6. Use sudo intentionally¶
sudo checks whether your account is allowed to run a particular command with elevated privileges. Use it for a known administrative task, not ordinary editing or compilation inside your home.
This optional command lists permitted operations and may request your account password. A key-based SSH login and passwordless sudo are separate policies. Password entry is not echoed.
For a configuration requiring administrator editing, use the documented tool for that configuration. If changing sudoers is genuinely necessary, use visudo so syntax is checked; do not paste a NOPASSWD: ALL rule as a beginner convenience. A wrong rule can prevent further administration.
Creating, deleting or renaming accounts is not part of this exercise. Keep a tested administrator login and a recovery route before changing login policy.
7. Optional: add an SSH key without losing access¶
Run these in a Linux/macOS shell on the client computer, not in the Pi's SSH session. For Windows or another client environment, use its supported key-creation workflow in the official SSH reference below. These commands create a specifically named key, so they do not silently overwrite a commonly used default key.
If that path already exists, choose a new filename or use the existing key intentionally; do not approve overwriting it. Choose a passphrase for the private key. Only the .pub file may be copied to the Pi.
On a client that has ssh-copy-id, replace both the account and hostname:
ssh-copy-id uses your existing authorised login to install the public key. If it is unavailable on the client, follow the official SSH instructions instead of copying a private key or replacing authorized_keys.
Check: keep the original session open and establish a second login with the key. Identity verification and protection of the private key still matter. Adding a key does not automatically disable password login.
Do not disable password authentication or add an AllowUsers restriction until you have verified key login, effective server settings and recovery access. Those are separate security changes covered in Security Hardening.
Troubleshooting¶
| Symptom | Check before changing anything |
|---|---|
| File permission denied | id, ls -l and the permissions on parent directories |
New group absent from id |
Start a new login; inspect the account's membership |
| GPIO still inaccessible | Actual chip path, ownership, ACLs and whether another process has requested the line |
| sudo password rejected | The current account's password, keyboard layout and policy; SSH keys are unrelated |
| SSH key login denied | Correct remote account, matching public key, client key selection and server logs |
| A file created using sudo is root-owned | Confirm the exact file and expected owner; do not recursively change your entire home |
The non-administrative folder exercises can be tested without modifying account policy. Account creation, key deployment and sudo changes are not claimed as executed for this revision.
Check your understanding and continue¶
Can you explain why 600 works for a private file but a directory needs execute permission? Why does adding sudo hide rather than explain some errors? Why must a new login follow a group change?
Next, learn Storage Management. For hardware access, return to C++ Hardware Programming with a verified account and chip path.