how to create a zip with password in linux

How to Create a Zip with Password in Linux

A zip archive is a file format which is used to store compressed data. A zip file can store files and folders in multiple level of compressions, making it easier to archive, transport & manage a large number of files/folders.

In Linux zip files can be accessed or created using packages called zip & unzip. Both of these packages will either come pre-installed with your Linux system or you will need to fetch them from the repositories.

Here in this short tutorial I am going to show you how you can create a zip archive in Linux with password protection.

There are two ways to do it. You can either use the command line interface in Linux (often called terminal or console) OR if you are using a Desktop Environment such as Gnome, KDE, Xfce, etc, you can use GUI applications such as Ark, File Roller, and Engrampa.

Create a Zip file with Password in Linux (Using Terminal)

1. First step is to make sure that you have the correct utilities installed. If you are not already in the command-line interface (CLI), open the terminal and navigate to the location where the file that you need to add to zip archive are. You can do this easily with the cd command.

(Note: sudo is only needed if you are installing from a non-root account.)

2. Now type the following command (for Debian and Ubuntu based systems) :

sudo apt install zip unzip

For CentOS you will need to type:

sudo yum install zip unzip

And for Arch-based system, type:

sudo pacman -S zip unzip

3. With this done, verify that you are in the correct location and type ls in the terminal to verify that all of your files are there too.

4. Now type this is terminal.

zip -P password_here -r output_file_name.zip file1_to_add_to_archive file_2 folder_1

5. Hit enter.

The command may look confusing at first but let me explain with an example.

If I want to create a zip archive with ‘file1, file2, folder8, folder and file with space‘ in it with the password [email protected] and a file name archive.zip the command would look like this:

zip -P [email protected] -r archive.zip file1 file2 folder8 'folder and file with space'

After the command finishes executing, you can run the ls command to verify that your archive is there. To unzip the file, simply type this on your terminal:

unzip NameOfTheArchive.zip

It should now ask for the password & once you do the same, the content of the zip archive should be extracted.

Create a Password-protected zip in Linux (Using GUI)

There are many GUI programs that you can use to create zip files with passwords. But for this tutorial, I am going to use Ark. This main reason for this is the fact that Ark is Available in main repo’s of CentOS, Ubuntu, Debian, & as well as Arch Linux; Also it is very easy to use.

1. First install Ark from the app store that your Linux distribution provides. You can also use the terminal to do so, here are the commands:

For Ubuntu/Debian based Systems:

sudo apt install ark

CentOS:

sudo yum install ark

For Arch based Systems the command is:

sudo pacman -S ark

2. After the installation is successful, open a file manager and navigate to folder where the data that you want to zip is.

3. Select the files and folders that you want to archive as a password-protected zip, right-click, click on “Compress” and select “Compress to”.

Sleect compress in right-click menu to create a zip with password

4. Enter the file name, and set the type to application/zip. After that, click on Password Protection menu and set a password for your zip file.

set archive type to zip and choose a password

5. Click ok, let it process and you should now have a password-protected zip file with your stuff in it.

6. If for some reason you don’t get the right-click menu entry for Compress, here is an alternate way to do it.

7. Open Ark either from your app drawer or terminal, click on Archive on the top menu and select New.

8. Again, enter a file name, set type as application/zip and set a password using the Password Protection menu.

9. Now simply drag and drop your files into the Ark window to add them to your zip archive.

Dragging files to zip archive in ark

Can I Password Protect an existing Zip file

No it is not possible to add a password to an existing zip file. But what you can do instead is unzip the contents of the zip file and create a new archive with the methods above.

Related: How to Unzip in Linux.

If you are looking for other ways to secure your data, checkout this post on how to encrypt a drive (or partition) in Linux. An encrypted drive is better than a zip because you can add more file to it later on and also access and change the content without any hassle.

Leave a Reply

Your email address will not be published.