Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Lock Files and Folders in Mac OS X

· 5 min read · Home Tech

In this article
  1. What Locking Actually Does
  2. How to Lock a File or Folder
  3. What Locking Does NOT Do
  4. Using Terminal to Lock (The Stronger Way)
  5. Locked Folders and What Happens Inside
  6. When Locking Is Useful
  7. Frequently Asked Questions

To lock a file or folder in macOS, select it in Finder, press Command-I to open the Get Info window, and check the Locked checkbox. This prevents the item from being modified, renamed, or moved to the Trash until you unlock it again.

What Locking Actually Does

Locking in macOS is a per-item attribute stored in the file system metadata, not a security feature. It protects against accidental changes: a locked file cannot be edited, overwritten, or deleted through the normal Finder interface. Apps that respect the lock will show a warning or fail to save changes. Locked folders behave slightly differently—you can still add files to a locked folder, but you cannot rename, move, or delete the folder itself.

How to Lock a File or Folder

  1. Open Finder and navigate to the item you want to lock.
  2. Select the file or folder.
  3. Press Command-I (or go to File > Get Info).
  4. In the General section, check the box next to Locked.
  5. Close the Get Info window. The change takes effect immediately.

To unlock, repeat the steps and uncheck the box. You can also lock multiple items at once by selecting them all before pressing Command-I—the Get Info window will show a single Locked checkbox that applies to all selected items.

What Locking Does NOT Do

Locking is not encryption. Anyone with access to your Mac can unlock the item in seconds—no password is required. It also does not prevent the item from being read, copied, or shared. If you need to keep the contents private, you must use FileVault (full-disk encryption) or create an encrypted disk image via Disk Utility.

Another common misconception: a locked file can still be deleted if you use the rm command in Terminal. The lock is a Finder-level convenience, not a system-level protection. Terminal commands bypass it unless you also set the file's uchg flag (user immutable), which requires an admin password to change.

Using Terminal to Lock (The Stronger Way)

For a more robust lock that even Finder respects more strictly, you can use the chflags command:

chflags uchg /path/to/file

This sets the user immutable flag. To unlock:

chflags nouchg /path/to/file

The uchg flag prevents the file from being modified or deleted even by Terminal commands, and it shows a lock icon in Finder. To see all flags on a file, use ls -lO (letter O, not zero). This method is closer to what you might expect from a "lock," but it still does not encrypt anything.

Locked Folders and What Happens Inside

Locking a folder does not lock its contents. You can still create new files inside a locked folder, edit existing files, and delete files from within it. The lock only applies to the folder itself—its name, its location, and its existence. This is a common source of confusion. If you want to lock everything inside a folder, you must lock each item individually, or use a different approach like moving the folder into a disk image that you mount read-only.

When Locking Is Useful

  • Preventing accidental edits to important documents, like a final draft or a spreadsheet you reference often.
  • Keeping files out of the Trash—a locked file cannot be dragged to the Trash, and if you try, macOS asks for confirmation and then refuses.
  • Protecting configuration files in your home folder from being overwritten by apps.
  • Preserving a folder's name so you don't accidentally rename it while working nearby.

Locking is not a substitute for version control or backups. For documents you actively edit, consider using a versioning system like Time Machine or a cloud service with version history.

Frequently Asked Questions

Can I still copy a locked file?

Yes. Copying a locked file produces an unlocked copy. The lock attribute is not carried over to the new file, so the copy is fully editable. This is useful if you want to work on a copy while keeping the original pristine.

Why does my locked file still show a lock icon after I unlock it?

The lock icon in Finder may take a moment to refresh. Try pressing Command-R to reload the Finder window, or log out and back in. If the icon persists, check whether the file also has the uchg flag set via Terminal—unlocking via Get Info only clears the Finder lock, not the immutable flag.

Can I lock a file on an external drive or USB stick?

Yes, but only if the drive is formatted with a file system that supports the lock attribute, such as APFS or HFS+. On FAT32 or exFAT drives, the Finder lock option is grayed out because those file systems do not support it. You can still use chflags on some external drives, but it may not persist after unmounting.

Does locking a file protect it from ransomware or malware?

No. Malware running with your user privileges can unlock the file just as easily as you can. Locking is a manual convenience, not a security boundary. For real protection, keep backups and use macOS's built-in security features like Gatekeeper and FileVault.

How do I lock a file on macOS Sequoia or Sonoma?

The steps are identical across recent macOS versions. The Get Info window has looked the same for over a decade. If you don't see the Locked checkbox, make sure you are looking at the General section at the top of the window, not the More Info section.

Can I set a password to lock a file?

Not with the built-in lock. For password-protected files, use File > Export in apps like Pages or Numbers to create an encrypted copy, or create an encrypted disk image in Disk Utility. Those methods use AES-256 encryption and require a password to open.