When someone creates a new zip file, chances are, they have confidential data on there that they don’t want anyone else to see. Then it’s good to know how to create password-protected (or encrypted) zip files to secure their contents. That way, the data should stay safe even if someone intercepts or steals them off a drive.

This short guide will provide easy to follow instructions for those who want to create encrypted zip files on a Linux PC.

There are many different ways to encrypt zip files in Linux. This tutorial sticks to the zip command method. It is a built-in method that will work regardless of the distribution you use/ And you won’t need additional tools.

Before you begin, make sure you have zip installed. If the zip utility isn’t on your PC yet, install it using the distribution’s package manager before starting with the first steps in this tutorial.

How to Create Password Protected Zip Files Using Command Line

For this guide, let’s use an example file and directory called “testfile” and “testdirectory” accordingly. Replace the names with those of the files and directories that you want to encrypt.

There are two main ways to encrypt a zip file using the command line. Both these methods are almost identical to creating a standard zip folder in Linux. They only have a few minor differences.

Method 1

1. Select the files or directory that you want to encrypt.
2. Enter the zip command with the -P flag command. Note that those wishing to add any directories to the zip file should add -r to the command line as well. It should look something like this:

Unfortunately, you enter the password in plain text in the command line using this method. It is an insecure way to go about it. Especially since the password will also stay in plain text in the history file. It allows anyone with access to the account to see the password.

That is why method 2 is the preferred method — it’s more secure.

Method 2

1. Select the files or directory that you want to encrypt.
2. Enter the zip command with the -e option to create an encrypted zip file. There’s also an alternative method using --encrypt, but the outcome is the same. Note that those wanting to add any directories to the zip file should add -r to the command line as well. It will look something like this:

3. Then you will need to enter a password and verify it. The password won’t appear on the screen when you type it, for security reasons. But make sure to type in the same password each time and press enter after each.

Things to Remember About These Encrypted Zip Files

There are a couple of things to remember when creating password-protected zip files, regardless of the method used.
  • Should someone get hold of the zip file, they will be able to open it and see the files and directories stored there. But they will not be able to open those files or see what’s in them. So make sure that the names of the files don’t give away any confidential information either.
  • Once you set a password for an encrypted zip file, you cannot change it. So remember it or store it somewhere safe.
  • If you plan to share those files, remember to provide the recipient with the correct password. Sharing passwords in a secure way is also essential.

Secure Storing and Sharing of File Passwords

How many encrypted zip files do you plan to create? You may end up having many unique (and sometimes difficult to remember) passwords.

If that’s the case, then it is time to look into a password manager so that the passwords for these files don’t get lost. Or worse, saved in plain text somewhere and stolen.

Premium password managers can handle an unlimited number of saved passwords. Plus, some can save notes as well. It makes them the perfect option for keeping track of which passwords go with which zip files.

If you plan on keeping encrypted zip files on a couple of different devices, look into a password manager with a backup and sync feature. It’s much more convenient to share the password manager across many devices.

If you plan on sharing the said files, you can get one with secure sharing options. Then you won’t end up sharing passwords in plain text over messenger or other insecure platforms.


There is an easy way to create encrypted zip files in Linux using the GUI as well. But that’s a separate story for another day. The command-line methods outlined above should be more than enough for anyone looking to create encrypted zip files on Linux.
Share To: