Fixing File Ownership and Permissions in Your Home Directory on Raspberry Pi

Posted on November 21, 2025

If you've been tinkering with your Raspberry Pi and noticed some files in your home directory (~) have the wrong owner or permissions—maybe from running commands as root or copying from another system—this guide will help you reset them. We'll use chown for ownership, chgrp for group (though often combined with chown), and find with chmod for permissions. This is aimed at beginners on Raspberry Pi OS (the default Debian-based OS).

Step 1: Reset Ownership

To set the owner of all files and directories in your home to your user (usually "pi" on a fresh install), use chown -R. The -R makes it recursive. We'll also set the group to match.

sudo chown -R $(whoami):$(whoami) ~

Explanation:

If you want to use chgrp separately (for group only), it's similar: sudo chgrp -R $(whoami) ~. But chown handles both.

Step 2: Set Permissions with find and chmod

After ownership, set directories to 755 (readable/executable by all, writable by owner) and files to 644 (readable by all, writable by owner). Use find to target types.

For directories:

find ~ -type d -exec chmod 755 {} \;

For files:

find ~ -type f -exec chmod 644 {} \;

Explanation:

Use sudo if needed: sudo find ~ -type d -exec chmod 755 {} \;.

Full Script for Raspberry Pi

Here's a bash script to do it all. Save as fix_permissions.sh in your home directory.

#!/bin/bash

# Reset ownership
sudo chown -R $(whoami):$(whoami) ~

# Set directory permissions
sudo find ~ -type d -exec chmod 755 {} \;

# Set file permissions
sudo find ~ -type f -exec chmod 644 {} \;

echo "Done! Check with ls -l ~"

Instructions for New Users:

  1. Open Terminal on your Raspberry Pi (Ctrl+Alt+T or from menu).
  2. Create the file: nano ~/fix_permissions.sh (paste the script, Ctrl+O to save, Enter, Ctrl+X to exit).
  3. Set execute bit: chmod +x ~/fix_permissions.sh (makes it runnable).
  4. Run it: ./fix_permissions.sh. Enter password if prompted.
  5. Verify: ls -l ~ to see changes.

Warnings: Backup important files first. Don't run in / or other system dirs. If issues, reboot or check logs. In the script, replace ~ with your desired path if needed.