- 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
- Partitions: Planning Your Linux Installation¶
- What is a partition?¶
- What is a file system?¶
- Planning your partitions¶
- Swap¶
- root (/)¶
- /home¶
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.
Partitions: Planning Your Linux Installation¶
This article will explain some of the terms involved with partitioning your hard drive, as well as some concepts you will need to understand before installing Linux, and will help you determine what partitions you need to create for Linux.
What is a partition?¶
Imagine your company is moving into a new building that is set up like a warehouse. There are no internal walls, it’s just one big room for everybody to work in. Chances are, the first thing the boss is going to do is build himself an office (he wouldn’t want to associate with you workers), so he’ll have a partition set up, an internal wall to separate him from you. Next, each worker will get a cubicle in the big room with smaller partitions to separate you from the person next to you.
Hard drives work the same way. The disk gets partitioned into smaller, separate pieces which can belong to different owners. In our case, Windows might own some and Linux will own others. On hard drives though, the word “partition” does not refer to the wall itself, it refers to the separated space. So we say Linux is installed “on” the first partition.
What is a file system?¶
Ever go looking for a book in the library? In order to find what you’re looking for, you must understand the library’s file system, or method of organization. Fiction books are easy, they use a simple type of file system commonly known as alphabetical by author. Nonfiction books can be tougher because they use a different type of file system, the Dewey Decimal System. What if you don’t understand the Dewey Decimal System? What if you only know the title of a book and you don’t know whether it’s fiction or non-fiction? How can we find our book now? Luckily there is a librarian to help us, and she has created a card catalog (or in most libraries now, a computerized catalog) listing all the books available and where to find them.
Now, picture your hard drive as the library. Like the library, your hard drive can have different file systems. The operating system is your librarian, who has provided the directory tree (sometimes also referred to as “the file system”, with a slightly different meaning) as a catalog of the files available.
Unfortunately, the world of computers is not as standardized as our libraries. In computers, every librarian or operating system has its own type of file system, and other operating systems often don’t know how to read it. Lucky for us, Linux is a versatile operating system and it does understand the file system used by Windows 95 and Windows 98, as well as many others.
Planning your partitions¶
Each distribution’s installation guide contains (or should contain) a section on partitioning your hard drive. I have noticed, however, that the manuals often include far more detail than is necessary in a typical desktop installation, and can be confusing to new users.
Personally, I favor the KISS principle (Keep It Simple, Stupid), especially for beginners. If you are installing a server that will serve multiple user’s simultaneously and provide myriad services, you will want to read these manual sections as well as the Partition Mini-HOWTO, an excellent document detailing the reasons one might want to create the seven or more partitions sometimes recommended in these primers.
For a single-user desktop system, you can ignore just about all of that. Desktop systems for personal use don’t have most of the complications that require so many partitions. For a healthy Linux installation, I recommend three partitions: swap, root, and home.
Swap¶
You need one partition that will be used as Linux swap space. This is space on your hard drive that can be used as virtual memory. Virtual memory allows your computer to run large programs and perform complex tasks even if it does not have enough physical RAM to do the job. (It is a lot slower, but it works.)
The amount of swap space required is a matter of religious argument among geeks and hackers, and entire volumes could be written about the subject. To keep it simple, create one swap partition that is 50% to 100% the size of the physical RAM in your system. If you are short on RAM with plenty of drive space, go large. If you’re short on drive space and have lots of RAM, go small.
root (/)¶
The root file system is represented by a forward slash (/). It is the top of the directory tree, and contains Linux and everything that you install with Linux. (See The Linux (Virtual) File System for details). This is roughly equivalent to your “C:” drive under DOS or Windows. You must create a partition for the root directory. (Don’t confuse this with the “root” user account, who is the administrator of the system. That’s a different kind of root!)
The size of your root partition will vary depending on what you install or plan to install. Check your distribution’s documentation, and reserve enough space for a maximum installation, plus at least 100MB more for temporary space and installation of new software. If you plan to download and try out lots of software, leave more space. If you have a small hard drive, you can trim back on your installed packages to save space.
In general, you should be fine with a root partition between 2GB and 8GB.
/home¶
The third and final partition you should create will hold your /home directory. This is the place where all the user-specific files, your data in other words, are stored. It is roughly equivalent to the “My Documents” folder on a MS Windows desktop (if you have MS Office installed). On a multi-user system, each user will have her own directory under /home .
Strictly speaking, it is not necessary to create a separate partition for /home . If you do not, it will reside on the root partition like everything else. If you are cramped for space, you may need to configure your machine this way.
The reason I recommend creating a separate partition is that you are a new user. You are going to want to play with things, experiment, push the limits of your system. Before long, you will break something so badly that you will need to reinstall, or you’ll just want to reinstall with different options, or try a different Linux distribution. Having /home on a separate partition makes it very easy to wipe out and reinstall Linux without losing any of your data.
Don’t think to yourself, “I’ll be careful, I won’t need to reinstall.” Wrong. You will definitely hose up your system at least once, and for the novice, reinstalling is often the easiest way to fix it. I had ten years of computer experience and worked in technical support when I started with Linux, so I knew my way around a PC, and I had to reinstall twice. Just plan on it and make it easy on yourself. Keep your data on a separate /home partition, or keep it backed up on some other medium, and be sure to create the boot floppies when prompted to do so during the installation process. They have saved my system more than once.
And don’t get the wrong impression here. This reinstall problem is only because you are a new user, still learning. Six months from now your system will be purring like a nursing kitten, and you’ll go weeks or months without rebooting, let alone reinstalling.