Linux & Open SourceTechnology

How to Take Ownership of Files on a Linux Drive That Show as Owned by Root

Admin
How to Take Ownership of Files on a Linux Drive That Show as Owned by Root

You copy files from an old drive, restore a backup, or mount a disk from another Linux system, and suddenly you cannot edit your own files. The file manager shows a lock icon, saving fails with a permission error, and a quick look in the terminal shows the owner as root. This is one of the most common Linux permission problems, and the fix is a single command once you understand what ownership means.

This guide explains why files end up owned by root, how to take ownership safely with chown, how to fix a whole folder or an entire mounted drive, and how to avoid the traps that can break a system if the same command is used in the wrong place.

Quick Answer

Take ownership of a file with sudo chown yourusername file.txt, and of a whole folder and everything inside it with sudo chown -R yourusername:yourusername /path/to/folder. Replace the name and path with your own, which you can confirm with the whoami and id commands. Never run a recursive chown on system folders such as /, /etc, or /usr.

Why Files End Up Owned by Root

Every file on a Linux system has an owner, a group, and a set of permissions that say who can read, write, and run it. The root user is the all-powerful administrator account. Files created by root, or by a program running with sudo, belong to root. Your normal user can often read them, but cannot change or delete them.

There are several everyday ways root-owned files land in your folders.

  • You ran a program or a copy command with sudo, so everything it created belongs to root.
  • You restored a backup or extracted an archive as root, and the original ownership came with it.
  • You mounted a drive from another Linux computer where your user had a different user ID number, so the files display as root or as an unknown user.
  • You copied files from a system drive or a rescue USB, where working as root is normal.
  • A poorly behaved installer or script wrote files into your home folder while running with administrator rights.

Check Ownership Before Changing It

Always look before you change anything. Run ls -l in the folder, or ls -l /path/to/file for one file. The output shows the owner in the third column and the group in the fourth. Lines beginning with root root confirm the diagnosis. You can also run stat file.txt for a fuller report. Knowing the current state helps you notice if only some files are affected, which is common after a mixed copy from several sources.

Step 1: Take Ownership of One File or Folder

  1. Open a terminal and confirm your username with whoami.
  2. For a single file, run sudo chown yourusername file.txt. You will be asked for your password, which is normal.
  3. To set the group as well, use the colon form: sudo chown yourusername:yourusername file.txt. On Ubuntu, each user has a matching personal group with the same name, so this is usually the right form.
  4. Check the result with ls -l file.txt. Your name should now appear as the owner.
  5. Test by editing and saving the file. If it saves, the fix worked.

Step 2: Take Ownership of a Whole Folder Tree

The -R option means recursive. It applies the change to the folder, everything inside it, and every subfolder all the way down. This is the command most people actually need.

  1. Identify the exact top folder, for example /home/yourusername/Restored or a mounted drive at /mnt/old-drive.
  2. Run sudo chown -R yourusername:yourusername /home/yourusername/Restored, adjusting the path to yours.
  3. Wait for it to finish. A large drive with hundreds of thousands of files can take a minute or two, and no progress display is normal.
  4. Spot-check with ls -l in a few subfolders, including a deep one, to confirm the change reached everything.
  5. Open and edit a previously locked file to confirm real access, not just a new listing.

For a plain explanation of how owners, groups, and read-write permissions fit together, see our guide on Linux file permissions explained in simple terms for beginners.

Step 3: Fix Ownership on a Mounted Drive

External and secondary drives need one extra thought: the type of file system decides whether ownership even applies.

Drives Formatted as ext4 or Other Linux File Systems

These store real Linux ownership, so chown -R on the mounted folder works and the result is permanent. The user ID number is what is really stored, so if your ID differs between two computers, the same files may show a different name there. The first normal user is usually ID 1000 on both, which is why drives usually just work.

Drives Formatted as FAT32, exFAT, or NTFS

These Windows file systems do not store Linux owners at all. Linux invents an owner at mount time, which is why everything can appear as root. Running chown on them will fail or do nothing useful. Instead, set the owner in the mount options: unmount the drive, then mount it with sudo mount -o uid=1000,gid=1000 /dev/sdb1 /mnt/data, using your IDs from id. For a permanent setup, add the same uid and gid options to the drive’s line in /etc/fstab.

The official chown manual page on man7.org documents every option of the command, including the reference-file option that copies ownership from another file.

Step 4: Fix Permissions as Well When Needed

Ownership and permissions are partners. After taking ownership, you may find files are still read-only for everyone, a leftover from a backup or a DVD copy. That is a chmod job, not a chown job.

  1. For your own documents, a sensible setting is chmod u+rw for files, giving the owner read and write access.
  2. To apply a standard pattern to a restored folder, use find /path/to/folder -type d -exec chmod 755 {} + for folders and find /path/to/folder -type f -exec chmod 644 {} + for files. This gives you full control, while keeping files non-executable, which is safer.
  3. Be careful with the popular chmod -R 777 advice. It makes everything writable by every user on the machine and removes all protection. It is almost never the right fix for your own files once you own them.

The Arch Wiki guide to file permissions and attributes is a solid reference for the numeric modes and special bits if you want to go deeper.

Common Mistakes and Useful Tips

  • Running recursive chown on a system folder: A command like sudo chown -R user /etc or, worst of all, on / can break logins, security tools, and services that require root ownership. Only ever target your own data folders and mounted data drives.
  • Forgetting the path and changing the wrong tree: Type the full path, then re-read the command before pressing Enter. A short path like . in the wrong terminal window can change thousands of unintended files.
  • Assuming chown failed on a USB drive: On FAT, exFAT, and NTFS drives, ownership is set by mount options, not by chown. Use uid and gid instead.
  • Using sudo for everyday work afterwards: Once files are yours, work as your normal user. Continuing to use sudo creates new root-owned files and restarts the whole problem.
  • Tip: Use sudo chown --reference=goodfile.txt badfile.txt to copy ownership from a file that is already correct. It removes guesswork about names and groups.
  • Tip: Add -v for verbose output on a small batch to see each change as it happens, and use ls -ln to see numeric IDs when names look strange on a drive from another machine.

Conclusion

Files owned by root are a normal side effect of copies, restores, and administrator tools, and they are easy to reclaim. Check the owner with ls -l, use sudo chown for single items and sudo chown -R for whole folder trees, and remember that Windows-formatted drives take their owner from mount options instead. Keep recursive changes strictly inside your own data, add a chmod fix only if permissions are also wrong, and your files will be fully yours again.

Frequently Asked Questions

Is it safe to change ownership of files in my home folder?

Yes. Your home folder and everything in it should normally belong to your user. If a program created root-owned files there, taking ownership back with chown -R on that specific folder is the standard fix and will not harm the system.

What is the difference between chown and chmod?

chown changes who owns a file. chmod changes what the owner, the group, and everyone else are allowed to do with it. A root-owned file needs chown first. A file you own but cannot write to needs chmod.

Why does chown say “operation not permitted” on my USB drive?

Because FAT32, exFAT, and NTFS do not store Linux ownership. The driver controls the displayed owner through mount options. Remount the drive with your uid and gid and the files will appear as yours.

I changed ownership but the file still will not save. What now?

Check three things: the file’s permissions with ls -l, whether the drive is mounted read-only with mount, and whether the program itself opened the file read-only. A read-only mount, common with NTFS drives left hibernated by Windows, blocks saving no matter who owns the file.

Can I take ownership without the terminal?

Often yes. Open the file manager as administrator, right-click the folder, open Properties, and look for ownership settings. For large restored drives, the terminal is faster and shows errors more clearly.

Admin

Passionate about the intersection of style and storytelling. I simplify fashion trends and industry news into easy-to-follow advice, helping you stay stylish and informed in the fast-paced world of fashion.

Leave a Reply

Your email address will not be published. Required fields are marked *