How to Encrypt Files on Windows, macOS and Linux
In this article
Encrypting a file scrambles its contents so that only someone with the correct password or key can read it. This protects sensitive information like financial records, personal documents, or private keys if your computer is lost, stolen, or compromised. All three major operating systems offer built-in tools for this, though the methods differ significantly between Windows, macOS, and Linux.
What You'll Need
- Windows: Windows 10 or 11 Pro, Enterprise, or Education edition (Home edition does not support the built-in encryption tool used here). Alternatively, install the free 7-Zip software for a method that works on all Windows versions.
- macOS: No additional software is required; Disk Utility is built into every modern version of macOS.
- Linux: Access to the terminal and the GnuPG (GPG) package, which is pre-installed on most distributions (like Ubuntu, Fedora, and Debian).
Step-by-Step
Encrypting a File on Windows
Windows offers two primary methods. The first uses the built-in encryption available in Professional editions, while the second uses a free, open-source archiving tool suitable for all versions.
- Method A: Using Built-in Encryption (Windows Pro Only)
Right-click the file or folder you want to encrypt. Select Properties. On the General tab, click the Advanced... button. Check the box labeled Encrypt contents to secure data. Click OK, then click OK again in the Properties window. The file name will turn green, indicating it is encrypted. This encryption is tied to your user account password; if you lose that account or move the file to a USB drive, you may lose access. - Method B: Using 7-Zip (All Windows Versions)
Download and install 7-Zip from the official website. Right-click the file you want to encrypt. Navigate to 7-Zip and select Add to archive.... In the window that appears, look for the Encryption section. Enter a strong password in the Enter password and Reenter password fields. Ensure the Encryption method is set to AES-256. Click OK. A new file with the extension.7zwill appear in the same folder. This file is now password-protected and can be safely shared or stored.
Encrypting a File on macOS
macOS uses a feature called an encrypted disk image. This creates a virtual container that acts like a folder, requiring a password to open and view the files inside.
- Open Disk Utility. You can find it by pressing Command + Space to open Spotlight Search and typing "Disk Utility."
- Once Disk Utility is open, go to the menu bar at the top of the screen and select File > New Image > Blank Image....
- A dialog box will appear. Give your encrypted container a name in the Save As: field.
- Set the Size to be large enough to hold your file(s). If you are unsure, you can select "MB" or "GB" and enter a custom number.
- For Format, leave it as "read/write disk image."
- For Encryption, select 128-bit AES Encryption (Recommended) or 256-bit for higher security.
- Enter and verify a strong password. You can uncheck "Remember password in my keychain" if you want to be prompted for the password every time you open it.
- Click Choose, then click Save. A new file with the extension
.dmgwill be created. - Double-click this file to open it; you will be prompted for the password. Drag your files into the mounted volume. When finished, click the eject symbol next to the volume name in Finder to lock it again.
Encrypting a File on Linux
The most standard and secure way to encrypt a single file on Linux is using GPG (GNU Privacy Guard) in the terminal. This uses a passphrase to symmetrically encrypt the file.
- Open your terminal application.
- Navigate to the directory containing your file using the
cdcommand (e.g.,cd Documents). - Run the encryption command. Type the following, replacing
filename.txtwith your actual filename:gpg -c filename.txt - You will be prompted to enter and confirm a passphrase. Type your password and press Enter. Note that the terminal will not show any characters as you type for security reasons.
- GPG will create a new file in the same directory with the extension
.gpg(e.g.,filename.txt.gpg). This is your encrypted file. You can now delete the original unencrypted file if you wish. - To decrypt the file later, run:
gpg filename.txt.gpg
You will be asked for the passphrase you created earlier. Once entered, the original file is restored.
Common Mistakes
- Forgetting the Password: There is no "forgot password" button for local file encryption. If you lose the passphrase, the data is effectively gone. Store your passwords in a safe place.
- Leaving the Original File: When using 7-Zip or GPG, the original unencrypted file remains on your computer. You must securely delete or manually remove the original file after creating the encrypted version.
- Using Weak Passwords: Encryption is only as strong as the password protecting it. Avoid simple dictionary words. Use a long passphrase or a randomly generated password.
- Windows Home Edition: Users often look for the "Encrypt contents" checkbox on Windows Home edition and cannot find it. This feature is exclusive to Pro/Enterprise editions. Use the 7-Zip method instead.
Tips
- When using 7-Zip on Windows, you can rename the
.7zfile to.zipif the recipient does not have 7-Zip, though they will still need a password to open it. - On macOS, you can create a "Sparse Bundle" image in Disk Utility. This format grows as you add files, so you don't have to guess a fixed size beforehand.
- For highly sensitive files, consider using a dedicated password manager that offers secure storage, or a dedicated encryption tool like VeraCrypt for cross-platform compatibility.
Troubleshooting
- "Encrypt contents" checkbox is grayed out on Windows: This happens if you are using Windows Home edition, or if the file is not on an NTFS formatted drive. Use the 7-Zip method described above as a reliable alternative.
- "Bad password" error on Linux/macOS: Ensure you do not have Caps Lock enabled. If you used a complex password, try pasting it from a password manager to avoid typos.
- Cannot open .dmg file on another Mac: The password must be entered correctly. If the file was created with a specific encryption method, ensure the other Mac is running a relatively recent version of macOS to ensure compatibility.
- File won't fit in macOS disk image: If you underestimated the size, you cannot simply resize it easily. Create a new larger disk image, copy the files over, and delete the old image.
Frequently Asked Questions
Is file encryption the same as putting a file in a password-protected zip?
Functionally, yes. When you use a tool like 7-Zip with AES-256 encryption, it is effectively a password-protected zip file. However, standard zip encryption can sometimes be weak; always ensure you are using AES-256 for strong security.
Can I email an encrypted file?
Yes, you can attach the encrypted file (.7z, .gpg, or .dmg) to an email. The recipient will not be able to open it without the password. You must share the password with them through a different channel, such as a text message or a phone call, for security.
Does encrypting a file slow down my computer?
For the methods described above, the impact is negligible. The file is only being processed while you are encrypting or decrypting it. It does not consume resources while it sits idle.
What happens if I change my computer login password?
If you use the built-in Windows encryption (Method A), changing your login password through the normal Windows settings usually preserves access to your encrypted files. However, if an administrator resets your password, you may lose access to those files permanently.
Is there a way to encrypt a file without a password?
Not securely. Encryption requires a key to lock and unlock the data. This key is typically derived from a password. Biometric unlock (like FaceID or TouchID) is a convenience layer that handles the password entry for you, but a password or PIN is still required as a backup.