Lock a Directory on Mac and Linux: Flags, Permissions and Encrypted Images

Neither macOS 13 and newer nor a typical Linux install has the Windows permission dialog, so locking a directory there means different tools: a lock flag on the Mac, the immutable bit on Linux, and encrypted images or containers when the contents must stay unreadable. This page gives the commands, and the limits of each.

Editorial TeamNovember 20267 min readLast verified: November 2026
Quick answer

On a Mac, tick Locked in Get Info or run chflags uchg to stop edits, and create an encrypted disk image to hide contents. On Linux, run chattr +i for the immutable bit and chmod 700 for privacy from other users. Only encryption protects a copied disk.

At a glance
Applies tomacOS 13 or newer; Linux on ext4, xfs or btrfs
Time needed2 minutes for a flag, 10 minutes for an encrypted image
DifficultyEasy in Finder, moderate in Terminal
Needs admin or rootNot on Mac for your own files; yes for chattr on Linux
Part ofthe lock directory guide
Two terminal panels showing a lock flag command for a Mac folder and an immutable attribute command for Linux % chflags uchg ~/Projects/TaxesmacOS: user-immutable $ sudo chattr -R +i /srv/recordsLinux: immutable bit A flag stops edits.An encrypted image stops reading.Pick by what you must prevent.
macOS

Mac: Lock a Folder With Finder and Terminal

On a Mac, select the folder, press Command-I and tick Locked, or run chflags -R uchg on the path in Terminal. The user-immutable flag blocks edits and deletions but not reading, and the owner can clear it. The flag also stays on one Mac, because iCloud Drive does not sync it.

Select the folder and press ⌘ + I to open Get Info. The Locked box is the same flag that chflags uchg sets. On a folder it stops items from being added or removed, while files already inside keep their own flags, so Terminal's recursive switch is the way to cover everything.

Terminal, freeze a folder and its contents
chflags -R uchg ~/Projects/Taxes
ls -ldO ~/Projects/Taxes
# undo
chflags -R nouchg ~/Projects/Taxes

The Eclectic Light Company's testing found the flag does not travel through iCloud Drive, so a folder locked on one Mac can look unprotected on the next. For privacy from other accounts, add chmod 700 ~/Projects/Taxes, which leaves the owner as the only user with access.

macOS encryption

Mac: Create an Encrypted Disk Image

An encrypted disk image is a file that behaves like a folder when mounted and like noise when closed. In Disk Utility choose File, New Image, Blank Image, pick 256-bit AES, set a password and a size. Do not tick the keychain box, because that lets every session on your account open it.

  1. Create the image

    Open Disk Utility, choose File, then New Image, then Blank Image. Name it, set a size, and choose a sparse bundle format so it grows as you add files.

  2. Choose the encryption

    Select 256-bit AES from the Encryption menu and set a password that you will also store outside the Mac.

  3. Mount, use and eject

    Double-click the image, enter the password, work in the mounted volume, then eject it. A closed image is unreadable without the password.

Terminal alternative
hdiutil create -size 2g -type SPARSEBUNDLE -fs APFS -encryption AES-256 -volname Private ~/Private.sparsebundle
No recovery

Apple's Disk Utility warns that data in an encrypted image cannot be recovered if the password is lost. Save the password in a password manager before you move any real files in.

Linux

Linux: Make a Directory Immutable With chattr

On ext4, xfs or btrfs, running sudo chattr -R +i on a directory sets the immutable bit, and the kernel then refuses to change or delete the contents even for root until someone clears it. Verify with lsattr, and remember the bit needs root or CAP_LINUX_IMMUTABLE to set or release.

Shell, freeze and check
sudo chattr -R +i /srv/records
lsattr -d /srv/records
# release
sudo chattr -R -i /srv/records

This is the one lock on Linux that overrides root's normal reach. Ordinary permissions do not: root holds CAP_DAC_OVERRIDE, which bypasses file permission checks, so chmod and chown only keep out other regular users. That is enough for a shared server directory and not enough against anyone with sudo.

Immutable bit

  • Stops edits, renames and deletes
  • Root must clear it first
  • Files stay readable

chmod 700

  • Keeps other regular users out
  • Root still reads everything
  • Blocks reading, not owner edits

For contents that must stay unreadable on a lost laptop, use an encrypted container such as a LUKS volume, or per-directory encryption on ext4 through fscrypt. Permissions and attributes do nothing once someone reads the raw disk.

Side by side

What Works on Which System

Hiding, restricting, freezing and encrypting exist on all three systems, but under different names and with different limits. The table maps each job to the Windows, macOS and Linux tool, so you can move a habit from one machine to another without assuming the same behavior.

The same job, three systems
JobWindowsmacOSLinux
Hideattrib +h +schflags hiddenLeading dot in the name
Restricticacls deny ruleschmod 700chmod 700, chown
FreezeDeny Write and DeleteLocked flag, chflags uchgchattr +i
EncryptEFS on Pro, archivesEncrypted disk imageLUKS, fscrypt
Root or admin can undo?Yes, by taking ownershipOwner clears the flagRoot clears the bit
Dedicated software

A Dedicated Locker for the Mac

When Terminal commands feel fragile, a dedicated locker gives the Mac a graphical front end. Folder Lock for Mac targets macOS 13 Ventura or newer and was announced in December 2025 beside the Windows 10.1.13 update, with the same $39.95 price listed for both editions in that announcement.

The Folder Lock for Mac edition keeps files in lockers, and its screens list a Desktop locker, a Dropbox locker, a Google Drive locker and a Mobile locker for syncing with the phone app. The Cloud tab lets you pick which lockers show up on the main screen and which open automatically at sign-in.

Its limits mirror the Windows edition: encrypted files need the password, and the vendor states there is no backdoor. It is a separate product from the Windows installer, so a Windows locker is not opened by the Mac app on its own, and phones use the iPhone and iPad app instead.

The launch announcement for the Mac edition carries the version and price details.

Try Folder Lock free →

Folder Lock for Mac main window with Google Drive, Mobile, Desktop and Dropbox lockers listed
The Mac lockers list
Folder Lock for Mac Cloud tab selecting which lockers show on the main screen
The Cloud tab and the Auto Open column
Monitor icon representing the desktop Mac edition of the locking software
Common question

Questions About Locking on Mac and Linux

Six questions cover the points where the Mac flag and the Linux immutable bit surprise people: deletion protection, what root can still do, iCloud sync, reading, filesystem support and a forgotten image password. Open a question for a short direct answer.

Yes against accidental changes, not against its owner. The Locked checkbox sets the user-immutable flag, so items cannot be added to or removed from a locked folder until the flag is cleared. The owner can clear it in Get Info or with chflags nouchg, so treat it as a guard against mistakes.

Not permanently. The immutable bit blocks modification, deletion and renaming even for root, but root can clear it with chattr -i and then delete. That makes it a strong guard against scripts and accidents, and a weak one against anyone who holds administrator access.

No. The Eclectic Light Company reported that the flag is not synced through iCloud Drive, so a folder locked on one Mac can appear unprotected on another. Apply the flag again on each Mac, or keep an encrypted disk image outside the synced folders.

Yes. The flag stops changes, not reading, so anyone signed in to your account can still open the files in Finder or Terminal. For privacy from other people on the Mac, use an encrypted disk image and leave the keychain box unticked when mounting it.

Ext4, xfs and btrfs support the immutable bit, and lsattr confirms it after you set it. FAT-style and many network filesystems return an error or ignore it. Setting the bit needs root or the CAP_LINUX_IMMUTABLE capability, so a normal user cannot freeze or release a directory.

The contents cannot be recovered. Disk Utility warns that data in an encrypted image is not recoverable if the password is lost. Check your password manager first, and if you ticked the keychain box when mounting, the saved password may be retrievable from Keychain Access on that Mac.

Back to the free methods overview, or see the full alternatives ranking.