There are many times when I have to upload a zip file to a server. However, sometimes I need that file to be protected. There are many files that we have that may be sensitive. Perhaps you are worried that someone will pirate your file. Here is a recent private picture of me to download. See if you can guess what the password is?
Protecting Files, Images,Videos and More
Many times I have to make proposals and no one needs to see it except for me and the client. So I password protect the zip file. It's pretty easy to do with the default windows file explorer. All you have to do is highlight all the files that you want to include, right click, then send to, Compressed Zip Folder. When the box pops up you can choose your security settings and enter a password. However, if you have a lot of files like an entire website, or a large video file, this process could take a while.For this I like to use 7 Zip.
Why I Like 7 Zip
Well the first reason is it is fast. Yes the person I am sending it too should have it installed as well, but that is a small price to pay for the speed and security that you get.
Install 7 Zip
It's so easy to install 7 Zip. Here are the different operating systems and how you do it.
Windows
In windows the process is so easy. Go to https://www.7-zip.org/ donwload and install.
Mac
Yes Mac is just as easy, go to https://www.7-zip.org/ and follow the regular procedure to install.
Linux
Now many of you that follow my posts know that I work a lot on Linux and even use Linux servers like the one you are on right now reading this. Here is the process.
Open up your terminal and type in this in order.
On Daien or Ubuntu
sudo apt update
sudo apt install p7zip-full
On RHEL or Cent OS
sudo yum install p7zip
How to Compress A File With Password Protection
So now that you have it installed you need to know how to password protect your files. Here is how you do that on the different Operating Platforms.
Windows
- Highlight the file or files you want to zip and protect
- Right click
- Select 7Zip
- Select Add To Archive
- When the box appears make sure you select the settings like the image below.
- Enter a password then click OK!
- Within a few seconds it will zip and secure all the files that you selected.
Here are a couple images to help you visualize the process.
Then...
Mac
The process is similar on a Mac.
Linux Systems
Ok, when you need to do this in a windows you just follow the same procedure. However, for us Geeks and developers. Here are the terminal commands.
The Syntax
7z a -p[password] -mhe=on archive.7z file_or_directory
Here is a better example.
7z a -pMySecretPassword -mhe=on secure_archive.7z myfile.txt
Extracting a 7zip File
If you need to extract a file on your server do this.
Navigate to the file.
cd /path/to/downloaded/file
Then Extract it
7z x file.7z
My Favorite Secure Zipping and Extracting
My favorite way to zip a file with 7zip and then extract it is like this.
On Windows or Mac
1st I'll select all the files I want to zip securely.If I am on Windows this is a 2 step process. I will use .tar and zip that way. This is so that all the permissions in the files stay the same. Then I will take that .tar file and 7zip it with a password to keep it secure.
On Linux
Navigate to the files and folders that you want to .tar.
cd /path/to/files
Use the tar command to combine those files and folders into an archive.
tar -cvf archive.tar file1.txt file2.txt folder1
-c: Create a new archive.
-v: Show the progress (optional).
-f: Specify the archive name (archive.tar).
This will create a single file named archive.tar containing file1.txt, file2.txt, and folder1.
Now Securely Compress the tar archive with 7z
7z a -pYourPassword -mhe=on archive.7z archive.tar
a: Add files to the archive.
-pYourPassword: Specify the password (YourPassword).
-mhe=on: Encrypt the file list so that the archive contents are hidden without the password.
archive.7z: The output .7z file name.
archive.tar: The input .tar file.
Clean up the tar file after compressing with 7z.
rm archive.tar
Complete Workflow
# Navigate to the directory containing the files
cd /path/to/files
# Create the .tar archive
tar -cvf archive.tar file1.txt file2.txt folder1
# Compress the .tar archive with password protection
7z a -pYourPassword -mhe=on secure_archive.7z archive.tar
# Optional: Remove the .tar file
rm archive.tar
Extracting
On Windows
Now to extract the file on Windows, I'll just right click > 7zip > Extract Files.
On Linux
Install p7zip (if not already installed)
sudo apt update
sudo apt install p7zip-full
Navigate to the directory containing the .7z file
cd /path/to/directory
Extract the .7z file
7z x latest.7z
Extract the .tar file
tar -xvf myTarFile.tar
Notice you can give the tar files and the 7z file different names.
Alternatives For Zipping and Securing Files
There are alternatives that you can use from 7Zip. There is WinZip7and Win-RAR. This one is called PeaZip, cute name but I have never used it. There are also paid versions like PKWare. Now I am sure all of those programs work good but my favorite is 7 Zip.