If you sometimes share your Linux PC with others, you probably want to hide personal files from nosy family and friends. You can easily hide files and folders in Linux by putting a dot (.) in front of the file or folder name.
But if any of your family and friends are tech savvy at all, they will know how to view your hidden files and folders. So, you need a less obvious way of hiding files and folders. You can use a form of data encryption called steganography, which is hiding information inside a normal image file.
We’re going to cover two ways to hide files in an images, one using the command line, the other using a graphical tool called Steg. I’ll also show you how to securely delete your original files, so they can’t be recovered.
Hide Files in an Image Using the Terminal
To begin, press Ctrl + Alt + T to open a Terminal window and create a new folder . Copy or move the image file (PNG or JPG) you want to use into that new folder.
Depending on the size of the files and how many you want to hide, you might want to use a big image so there is enough space inside the image to store the files.
Before you hide a file in an image using cmd, you’ll need to compress it.
Compress the Files You Want to Hide in a ZIP File
If you have multiple files to hide, you need to compress them into a ZIP file first. It’s easiest to do this when all the files are contained in one folder. Create a subfolder in the main folder you created and move the files to be hidden into that subfolder. For example, we have a folder called Images that contains an image file named MakeUseOf-Site.png and a subfolder called FilesToHide that contains the files to be hidden.
To compress your files into a ZIP file, use the cd command to navigate to the folder containing the image file and the folder containing the files to be hidden. Run the following command:
zip -r secret.zip FilesToHide/
The -r option in the above command recursively includes all the subfolders in the specified folder in the compressed file. Replace secret.zip with whatever name you want to use for your ZIP file. And replace FilesToHide/ with the name of the folder containing the files you want to hide.
Concatenate the ZIP and Image Files Into an Image File
Now we’re going to combine, or concatenate, the ZIP file and the image file using the cat command. In our example, we run the following command.
cat MakeUseOf-Site.png secret.zip > secret.png
MakeUseOf.png is our original image file and secret.zip is the ZIP file containing the files we want to hide. We direct those two files into a new image file called secret.png. Replace the three file names with the ones you used. The original image file must be listed first. Then, the file you’re hiding.
Use the ls command to list the files in the current folder. You’ll see the new image file you created. You can open the resulting image file in any image viewer or editor and see the original image.
To access the files hidden in an image file, press Ctrl + Alt + T to open a Terminal window, if one is not already open. Use the cd command to navigate to the folder containing the image with the hidden files.
Extract the ZIP file from the image using the following command.
Replace secret.png with the name you used for your image that contains the hidden files. When you type ls at the prompt, you’ll see your original folder containing the files you compressed. Use cd to open that folder and you’ll see your original files.
Securely Delete Your Original Files
Once you’ve hidden your files inside an image file, you should securely delete the original files. This is simple to do in Linux using the shred command.
Press Ctrl + Alt + T to open a Terminal window, if one is not already open. Use the cd command to navigate to the folder containing the files you want to securely delete.
In our example, we type the following command.
shred -z --remove HideThisFile.txt ThisFileIsPrivate.txt
By default, the files are overwritten three times. That is generally enough, but you can change that by adding –iterations=N to the command (before the file names). Replace the “N” with the number of times you want the files overwritten.
The -z option overwrites the files one final time with zeros to hide the shredding. The –remove option deletes the file. Isn’t that what shred does? Yes, but without the –remove option, the file will still appear as if it hasn’t been deleted.
For more information about the shred command, type man shred at the prompt.
Hide Files in an Image Using Steg
If you prefer to use a graphical tool to hide files in images, we recommend Steg. It has an easy to use interface and doesn’t need to be installed.
Download the Correct Version of Steg
Go to the download page for Steg and choose either the 32-bit or 64-bit version. If you don’t know whether you’re running a 32-bit or 64-bit version of Ubuntu, you can check in your system.
Go to System menu > About This Computer.
The Details dialog box displays. On the Overview screen, you’ll see either 32-bit or 64-bit.
Download the version of Steg that matches your system and save it in its own folder.
Compress Files You Want to Hide Using the File Manager
If you have multiple files to hide, you need to compress them into a ZIP file first. Open the File Manager and navigate to the folder containing the files you want to hide.
Don’t open the folder. Instead, right-click on the folder and select Compress.
Enter a name for the ZIP file in the Filename box and select .zip from the dropdown list to the right. Then, click Create.
Click Close on the dialog box that tells you the ZIP was created successfully.
Extract and Run Steg
Steg downloads as a compressed file in the .tgz format. Navigate to the folder where you saved the file. Right-click on the file and select Extract Here.
Open the resulting folder and double-click the steg program file.
Scroll to the end of the End-User License Agreement (EULA) dialog box and click Yes.
The first time you run Steg, a dialog box displays telling you where the settings will be stored. Click OK.
Hide the ZIP File in an Image
To hide your ZIP file in an image, click Open generic image to open the image you want to use.
On the Import image as uncompressed dialog box, navigate to the folder containing your image and select the image file. Click Open.
Steg shows the image twice, under Original Media and under Modified Media.
Before hiding your ZIP file in the image, you need to choose the encryption type and specify a passphrase. To do this, click Configuration on the toolbar. You can also go to Edit > Configuration on the menu bar.
If you’re just hiding files in the image for your own purpose, and not sending the image to someone else, you can use the symmetric cryptography mode. There are also three other cryptography methods available. You can read more about the about Steg’s cryptography modes in their help system.
For our example, we’re going to use the symmetric mode. On the Steg Options dialog box, select Symmetric PassPhrase (hide or extract) from the Crypto Options dropdown list.
Then, enter a PassPhrase. Your passphrase must meet all the requirements that display when you hover your mouse over the PassPhrase box. The PassPhrase box remains red until your passphrase meets the requirements. At that point, the box turns green.
You can also include a text message in the image. To do this, check the Embed a text message box and enter your message in the box below the check box.
Now we’re going to add our ZIP file to the image. Click Hide Data.
Navigate to where you saved your ZIP file, select it, and click Open.
A message displays once your data is successfully hidden. Click OK.
To save the modified image containing your hidden file, click Save.
Enter a Name for the modified image file and select the file type you want to use (.tif or .png). Navigate to where you want to save the image and click Save.
Extract a File That’s Hidden in an Image
To access your hidden files in an image, open Steg and click Open generic image on the toolbar.
Navigate to where you saved the modified image, select the image file, and click Open.
Click Configuration on the toolbar or go to Edit > Configuration.
Select the same Crypto Mode you used when hiding the file in the image and enter the same PassPhrase. The PassPhrase box remains red until your passphrase meets the requirements. At that point, the box turns green.
Click Extract Data on toolbar.
Navigate to the folder where you want to save the extracted file and click Choose.
A message displays once your data is successfully extracted. Click OK.
You’ll see the following files in folder where you extracted the modified image.
- README.txt: This file contains information about Steg and a URL for their website.
- <file name>: This is the file you hid in the image. In our example, it’s the secret.zip file.
- <file name>.sha1: This file contains the sha1 hash of the file hidden in the image.
- <file name>.txt: This file contains the optional text you embedded in the image on the Steg Options dialog box. If you didn’t embed any text in the image, this file will still be there, but it will be empty.
The file name for the .sha1 and .txt files include the extension for the file you hid in the image. So, it’s normal to see a file name like secret.zip.txt.
Steganography: More Useful Than Secure
Steganography is not the most secure way to protect your files, but it works if you just want your files to be less obvious to a nosy friend or family member who likes to pry into your life.
Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.