Linux home directory configuration

Change Home Directory in Linux

Change the home directory of a Linux user with a simple usermod command. While creating a user if you didn’t specify any –home parameter Linux assumes the home directory of the user to be /home/username even if you did specify you can later change it to something else according to your needs. Apart from changing the home directory using the usermod command you’ll have to assign proper ownership and permissions to the new folder. You can also change the home directory by editing the /etc/passwd file. I’ll outline both the steps here.

Change the home directory using usermod

This method is for command line warriors. Before you use the usermod command the new home directory should be created, ownership should be assigned to the new user and the folder should be chmoded correctly so that no one else can access it. Run the following commands to do it.
mkdir /home/new_home_directory
chown username:username /home/new_home_directory
chmod 700 /home/new_home_directory
usermod —home /home/new_home_directory username

Change the home directory by editing /etc/passwd

Alternatively you can also edit the /etc/passwd to change the home directory. But you should be careful not to edit anything else. Before editing this file it is always better to create the new home directory and assign proper permissions and ownership to it. Execute the following commands.
mkdir /home/new_home_directory
chown username:username /home/new_home_directory
chmod 700 /home/new_home_directory

Open the /etc/passwd file using a text editor and locate the line containing the required username it should look something like this
username:x:500:500::/home/username:/bin/bash

change it to
username:x:500:500::/home/new_home_directory:/bin/bash

Save the file.

Finally copy all the old content to the new home directory
cp -f /home/username/* /home/new_home_dir/

Источник

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.

Читайте также:  Find all symlinks linux

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:

Читайте также:  Linux показать структуру папок

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.

Источник

How to Change Default User Home Directory in Linux

Before we can jump into changing the default user home directory on a Linux operating system environment, we should brief through some theoretical and practical information related to the Linux home directory.

By definition, Linux is a multi-user operating system, which creates the need for a universal directory called the Home directory where different OS users can store and create personalized/user-centered files and directories.

These files and directories are only accessible to the homeowner (currently logged-in user). Therefore, each time a new user is created on a Linux environment, the user is associated with a unique home directory accessible only to that user.

On the other hand, the existence of these universal directories also permits a universal user (other than the homeowner) to have access to them. This user is known as root and can access all homeowner directories within a Linux system.

The syntax associated with a user’s Home directory is as follows:

Читайте также:  Check disk performance in linux

For instance, if a Linux system has a user called dnyce, then the absolute path to this user’s Home directory will be:

We can even list the permission settings associated with the user in the following manner:

List User Home Directory

This article will walk us through changing the default user home directory on a Linux operating system environment.

Benefits of Having a Linux Home Directory

We can summarize the benefits of having a Linux Home directory in the following manner.

  • User Access Restriction – It is only the homeowner and root user that can access this directory making it impossible for other users to tamper with existing customization settings and stored configuration files. Therefore, privacy and security are guaranteed.
  • Controlled Environment – Since multiple homeowners can exist within a single Linux system, their restriction on their Home directories is very advantageous. For instance, if a homeowner’s Home directory contains malicious code in stored executable files, the execution of this code will only affect that user environment and not the entire system.
  • Controlled Flexibility – The user’s Home directory is automatically created during the Linux installation. During this installation process, a user can decide to assign this directory an exclusive partition. This step makes it easier to execute backup and restoration tasks.

Changing Default User Home Directory in Linux

We will need to create a sample Linux user account for this tutorial to be more practical. Since creating a new user in Linux is associated with a Home directory, let us create one.

# useradd -m homeowner # passwd homeowner

The -m flag makes sure that a default user Home directory is created and set a password to the user.

Create New User in Linux

We can now switch to the newly created user account and confirm the default user home directory.

Check User Home Directory

Switch back to the root user account.

and create a new directory replacement for the default user Home directory.

We will assign user homeowner directory ownership for the newowner.

# chown -R homeowner:homeowner /home/newowner

Now, to change the user’s default Home directory from /home/homeowner to the new directory /home/newowner, we will make use of the usermod -d command in the following manner.

# usermod -d /home/newowner homeowner

The -d flag sets the directory.

Change Linux User Home Directory

We can switch back to the homeowner account and confirm the changes.

Confirm User Home Directory

Alternatively, we could set the preferred user Home directory during user creation in the following manner.

# useradd -m -d /home/newowner homeowner

The -d flag sets the directory.

While changing the default user Home directory, we might also need to migrate/move already existing user content to the new location. The usermod command to implement is:

# usermod -m -d /home/newowner homeowner

The -m flag moves the old directory content to the new one.

We can now easily change the default Home directory in Linux. I hope this article guide was helpful. Feel free to leave a comment or feedback.

Источник

Оцените статью
Adblock
detector