Protecting a file or folder
Method #1: Compression
The easiest way of safeguarding your files is to compress them and give them a password. On Linux, you can do this using the zip command.
zip -p <password> <zip-file-name.zip> <directory to zip>
# zipping multiple files with a password
zip -p <password> <zip-file-name.zip> <file 1> <file 2> … <file n>
Alternatively, you can encrypt it.
Method #2: eCryptfs
eCryptfs is a free and open-source code for encrypting and decrypting files and folders with passwords.
To install eCryptfs:
To use eCryptfs:
- Create an empty folder (ex: security)
- then type the following:
Ex: mount -t encryptfs security security
- It will ask you to choose a key type, choose one. It will also ask you for a passphrase, so specify a passphrase, and do not forget it! Next, it’ll ask you to specify a cipher, choose one. Then it will ask you for the key bytes; choose one (the longer, the better). Then, continue choosing. And you must remember your choices because when you want to decrypt them, you will have to provide this information.
- Now add the files you want to the security folder.
- Unmount it to encrypt it.
umount security
In order to decrypt the folder, you have to re-mount it (step 2), and then provide the same answers you provided during the first go. If your answers are not exactly the same, you will not be able to decrypt the folder!
Method #3: encFS
encFS is a free and open-source tool to encrypt and decrypt files and folders. In fact, encFS generates a virtual encrypted filesystem.
To install encFS:
To configure encFS:
mkdir -p /decrypt
encfs /encrypt /decrypt
Here, you’ll be prompted for a password, set it.
Then type:
cd /decrypt
Once you’re in the decrypt directory, add the files you want. Then unmount.
If you want to mount again later on, then type:
There are probably other encryption tools, but these are some of the most well-known ones.
Hiding Files and Folders
Hiding a file or a folder in Linux means that it will become invisible to the naked eye and other users. In such cases, only the creator can seek the file accurately enough.
Method #1: Adding a dot
Be it files or folders, you can add a dot in front of them and cause them to become partially invisible. What this means is that in such cases, the file will still be visible when the “ls -la” command is issued, but for those simply exploring the folder, it won’t be visible.
Ex:
mv myfile.txt .myfile.txt
# adding a dot in front of a folder
mv myfolder .myfolder
Method #2: Tilda
The next method is to use a tilda (~).
Ex:
mv myfile.txt ~/myfile.txt
# adding a tilda in front of a folder
mv myfolder ~/myfolder
Method #3: Nautilus-hide
Nautilus Hide is a free and open-source python extension to the Nautilus File Manager that basically hides a file or folder without renaming it. It uses .hidden folders to hide said files. Further, the best part about nautilus-hide is that files can be hidden with the click of a button. There’s no need for lots of code or even renaming anything; you simply click on the hide button, and the file is well hidden.
It does have a few dependencies which you must install:
- gettet
- python-nautilus
- xdotool
- nautilus
You can install all of the following via:
Then, let’s install nautilus-hide manually:
mkdir build
cd build
cmake [path to nautilus hide]
make
sudo make install
Restart nautilus
:
nautilus -q
Alternatively, you can also install it via command line:
Make sure that you restart your computer once the process has been completed. Now, please navigate to the file that you want to hide and RIGHT CLICK on it. It should give you an option to hide the files.
To view your files, you simply press Contorl+H (which will unhide the files). Pressing Control+H again will hide it again.
Protecting files is sometimes the only option to safeguard them. However, when you really want to protect your files from being seen, you can also resort to hiding them in plain sight. Much like a 2 step authentication, this 2 step process should keep your files fairly safe. In this tutorial, we learned about (I) protecting files and (ii) about hiding them in plain sight. We saw that there are many ways to carry these two steps out.
Happy Coding!