An Easy Way to Hide Files and Directories in Linux


As a Linux user, you might want to hide some of your files and directories from prying eyes. Perhaps you have sensitive data that you don't want others to see, or maybe you just want to keep your work organized. Whatever your reasons may be, hiding files and directories in Linux is a straightforward process that you can accomplish using various methods. In this article, we'll explore an easy way to hide files and directories in Linux, including several sub-headings and examples.

What is Hiding Files and Directories?

Before we dive into different methods of hiding files and directories in Linux, let's briefly discuss what this means. Hiding files and directories means making them invisible to regular users. In other words, these files and directories won't show up when you execute commands like "ls" or "dir." They'll still be there, but you won't be able to see them unless you use a specific method to display them.

Why would you want to hide files and directories in Linux? Well, as mentioned earlier, there could be several reasons. For example, you might have some sensitive data that you don't want others to access, or you might have some configuration files that you don't want to accidentally delete. By hiding these files and directories, you can ensure that they stay safe and secure.

Method 1: Using Dot (.) Prefix

The easiest way to hide a file or directory in Linux is by using dot (.) prefix. In Linux, any file or directory that starts with a dot is considered hidden. For example, if you want to hide a directory called "test," you can rename it to ".test." Here's how you can do it −

mv test .test

Similarly, if you want to hide a file called "document.txt," you can rename it to ".document.txt" by executing following command −

mv document.txt .document.txt

Once you rename file or directory, it will be hidden from regular users. However, you can still access it by using "ls" command with "-a" option. "-a" option shows all files, including hidden files. For example, to see all files in current directory, including hidden files, you can execute following command −

ls -a

Method 2: Using Hidden Attribute

Another way to hide files and directories in Linux is by using hidden attribute. This method is more secure than using dot prefix because it requires root privileges to set or unset hidden attribute. To set hidden attribute for a file or directory, you can use "chattr" command with "+h" option. For example, to set hidden attribute for a file called "document.txt," you can execute following command −

sudo chattr +h document.txt

Similarly, to set hidden attribute for a directory called "test," you can execute following command −

sudo chattr +h test

Once you set hidden attribute, file or directory will be hidden from regular users. However, you can still access it by using "ls" command with "-a" option. To unset hidden attribute, you can use "chattr" command with "-h" option. For example, to unset hidden attribute for file "document.txt," you can execute following command −

sudo chattr -h document.txt

Method 3: Using Permissions

The third method to hide files and directories in Linux is by using permissions. This method is more secure than previous two methods because it requires root privileges to set or unset permissions. To hide a file or directory using permissions, you need to set permissions to "000." "000" permission means that no one can read, write, or execute file or directory, including owner. Here's how you can set permissions to "000" for a file called "document.txt:"

sudo chmod 000 document.txt

Similarly, to set permissions to "000" for a directory called "test," you can execute following command −

sudo chmod 000 test

Once you set permissions to "000," file or directory will be hidden from regular users. However, you can still access it by using "sudo" command with "ls" command. For example, to see all files in current directory, including hidden files, you can execute following command −

sudo ls -a

In addition to methods mentioned above, there are also several third-party tools available that can help you hide files and directories in Linux. These tools often offer more advanced features and options than built-in methods, but they may require additional configuration and setup.

One such tool is "steghide," which allows you to hide files inside other files, such as images or audio files. This method of hiding is called steganography and is a more advanced technique than simply hiding files or directories. Steghide uses strong encryption to ensure that hidden data remains secure, and it requires a password to access hidden content.

To use steghide, you first need to install it on your Linux system. Once installed, you can use following command to hide a file inside an image file −

steghide embed -cf image.jpg -ef secret.txt -p password

This command embeds file "secret.txt" inside image file "image.jpg" using password "password." To extract hidden file, you can use following command −

steghide extract -sf image.jpg -p password

This command extracts hidden file from image file using password "password."

Another tool that you can use to hide files and directories is "Obsidian," which is a file encryption tool that allows you to create encrypted containers. These containers can store multiple files and directories and are protected by a password. encrypted container appears as a single file, which can be easily hidden using one of methods mentioned earlier.

To use Obsidian, you first need to download and install it on your Linux system. Once installed, you can create an encrypted container by using following command −

obsidian create -p password /path/to/encrypted_container.obsidian

This command creates an encrypted container with password "password" and saves it to specified path. You can then add files and directories to container using following command −

obsidian add /path/to/encrypted_container.obsidian /path/to/file_or_directory

This command adds specified file or directory to encrypted container. To access contents of container, you need to use Obsidian application and enter password.

Conclusion

Hiding files and directories in Linux is a simple process that can be accomplished using various methods. dot prefix, hidden attribute, and permissions are three ways to hide files and directories in Linux. While dot prefix method is easiest, hidden attribute and permissions methods are more secure because they require root privileges to set or unset. It's important to note that hiding files and directories doesn't make them completely inaccessible, and they can still be accessed by users with appropriate permissions. So, it's essential to keep sensitive data encrypted or stored in a secure location.

Updated on: 20-Apr-2023

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements