- Linux Home Directory | Explained
- What is the Purpose of a Home Directory, and Where is it Located?
- How to Access the Home Directory?
- Example 1: Access Home Directory Using cd /home Command
- Example 2: Using cd $HOME
- Example 3: Using cd “~(tilde)” Slash
- How to Check the Home Directory Permissions?
- Conclusion
- Linux Home Directory
- What Is the Linux Home Directory?
- Advantages of the Linux Home Directory or Partition:
- Enter Your Home Directory With Just a Command:
- The Home Directory Permissions:
- Conclusion:
- About the author
- David Adams
Linux Home Directory | Explained
In Linux, the Home directory (also called the “Login Directory”) is the default directory of a user. It contains the specific user’s files, data, and programs. Generally, it is the first workplace when the user logs in to the Linux system. Keeping this in view, this post provides a deep insight into the “home” directory.
The outline of this post is as typed below:
What is the Purpose of a Home Directory, and Where is it Located?
The main purpose of the home directory is also referred to as the personal workspace of a Linux user. Suppose the system has three users “itslinuxfoss”, “anna”, and “milton”. These users have the home directories like “/home/itslinuxfoss”, “/home/anna”, and “/home/milton”.
It is also used to store application configuration files, allowing users to customize their own environment and settings.
The “home” directory is generally present in the “root” directory. The “root” directory is the top-level directory that contains all the subdirectories, directories, and files present in the system. The “root” directory is denoted by the “(forward) slash (/)”.
The “home” directory is followed by the “~tilde” slash as shown below:
It denotes the “home” directory of logged-in user “itslinuxfoss”.
How to Access the Home Directory?
The user can easily access the home directory in the following ways:
Example 1: Access Home Directory Using cd /home Command
Suppose the logged-in “itslinuxfoss” user is in the “test ” directory as shown in the screenshot:
Execute the “cd(change directory)” command followed by the “/home” to move into the “home” directory:
The output shows that the “test” directory has been changed to “home” directory.
Example 2: Using cd $HOME
The user can also switch to the “home” directory by using the “$HOME” shell environment variable with the “cd” command in the following way:
The “$HOME” variable contains the full path of the particular user directory. In this case, it changed the “Downloads” directory to the “home” directory, which is verified by the “pwd” command.
Example 3: Using cd “~(tilde)” Slash
The “~(tilde)” slash is another way to access the “home” directory followed by the “cd” command. Now the “itslinuxfoss” user is in the “New2” present working directory:
Type the following “cd” command to access the “home” directory:
How to Check the Home Directory Permissions?
Each file and directory available in the Linux system has three types of permissions “r(read)”, “w(write)”, and “x(execute)”. These permissions are usually assigned by default and can also be modified per requirements.
To check the “home” directory permissions, use the following “ls” command with the combination of argument “l(list)” and “d(directory)”:
The output shows that the “itslniuxfoss” owner of the “home” directory has all the permissions (rwx). Whereas its associated group “itslinuxfoss” only has the “x(execute)” permission.
These default permissions are better for security as only the “itslinuxfoss” user can read, write and execute files in the “home” directory.
Conclusion
Linux “home” directory is the subdirectory/next-level of the “root” directory denoted by the “~(tilde)” slash. It also refers to the “Login Directory”, which contains the specific user files, directories, and subdirectories. Its default permissions are “750”, meaning only its owner has full rights. This post has briefly described all about the Linux “home” directory.
Linux Home Directory
In this article, you will learn both theoretical and practical information on the Linux Home directory, which stores all information related to the users.
After reading this tutorial, you will know what a Home Directory is, the permissions structure, and application scenarios. This is useful for Linux distributions and other Unix-based operating systems like BSD.
Practical instructions in this tutorial include screenshots, making it easy for any Linux user to follow them.
What Is the Linux Home Directory?
Contrary to Microsoft Windows, Linux was designed to be a multiuser and multitasking operating system. This means that Linux is optimized to be used by different users. This is also useful to interact within networks securely.
Linux systems include a universal directory named Home, whose parent directory is the root (/) directory as a multiuser operating system.
In other words, the Linux Home Directory or partition stores personal directories of each user, which is restricted only to the homeowner and root user.
Let’s say you have a user named linuxhint in your system and another user named systemuser, then the path for each user’s personal directory will be:
Where “/” is the root directory, home is the general directory or partition storing all personal account directories (e.g. linuxhint or systemuser).
The exception to this rule is the root personal directory, which is not located under the /home/ partition/directory but under the root system location (/root/).
Home Directories are followed by a tilde slash (~), as shown below:
Advantages of the Linux Home Directory or Partition:
As said previously, the Home of a user isolates or restricts access to user files. This includes customization settings. Here, you can store configuration files that will affect only the Homeowner.
As you can imagine, this includes executable files stored only under a user’s Home Directory, which can be executed only within the user environment specifically. This also prevents malicious code from infecting the entire system.
This is one of the main reasons Linux is a more secure operating system than Windows. Linux was natively created under the premise, while Windows, developed for personal use, patched its operating system to implement a similar feature. In contrast, Linux was developed to grant privacy and security to different users.
Like other operating systems, this directory is created automatically when installing your system. During the Linux installation process, you can assign the Home directory an exclusive partition. This will ease your backup and restoration tasks and just save them.
Enter Your Home Directory With Just a Command:
There are different commands to access your Home Directory immediately: cd, tile slash (~), and cd $Home.
A cd command example, where the user changes the current directory from the /usr to /home/username directory.
A cd $HOME command example, where the user changes the current directory from /boot to /home/username directory.
A cd ~ command example, where the user changes the current directory from /boot to /home/username directory.
You can use the pwd command example to show the current directory to learn if you are in your /home.
Note: you can move to other directories by typing cd /, such as cd /user and cd /boot. To access files and directories when the current path isn’t the /home directory, always add the /home/ path as the parent directory in the path.
The Home Directory Permissions:
Default permissions of the /home directory are drwxr-xr-x (755), allowing the user group to execute and read files and others to execute files within the Home Directory.
You can check your Home Directory permission as shown in the following image:
If you are looking for better security and privacy, you can change the default permissions to 750.
Below you can see the command execution and result:
As you can see, others can’t read or execute files now. The owner keeps full rights, and the group read and execution permissions.
The /home directory is a formidable way to manage the users’ files. This allows users to manage users’ privacy, to move an entire user dedicated directory storing one’s files, for example, for backup purposes.
The root user is the only one allowed to access all users’ Home Directories with full permissions. Use the privileged user (root) to change permissions globally in your system. Yet, other users have global rights when reading files. You can change specific directory permissions by running the last command explained in this tutorial. It is recommended to increase your privacy, changing permissions to a more private policy.
Learning Linux permissions will allow you to customize your file access, as shown previously. You can get additional information on changing Linux permissions here. Understanding the home directory theoretic is useful to deal with other operating systems aside from Linux, like the BSD-based systems. In Macintosh, users, the equivalent to the /home directory is /users/, where users directories are /users/username.
Conclusion:
The Home Directory, as a separate component of your system filesystem, shows Linux as the superior structure of this operating system over others; even over other systems, which didn’t include the multiuser feature natively, patching it later. Learning Linux permissions will allow you to customize your file access, as shown previously.
Thank you for reading this Linux tutorial about the /home directory. I hope it was helpful for you to understand more about Linux. Keep following Linux Hint for more Linux professional articles.
About the author
David Adams
David Adams is a System Admin and writer that is focused on open source technologies, security software, and computer systems.