• About Us
  • Privacy & Policy
HowTo's
  • Home
  • Commands
  • Linux
  • SCM
  • Git
  • Database
  • MySQL
  • Kubernetes
  • Docker
No Result
View All Result
  • Home
  • Commands
  • Linux
  • SCM
  • Git
  • Database
  • MySQL
  • Kubernetes
  • Docker
No Result
View All Result
HowTo's
No Result
View All Result
Home Commands

Customizing Home Directory Paths for Users in Linux

June 21, 2024
in Commands, Linux, Linux Command Tutorial, Linux Commands
A A
0
12
SHARES
107
VIEWS
Share on FacebookShare on Twitter

The useradd command in Linux is used to create new user accounts. One of the options available with useradd is -d, --home-dir HOME_DIR, which allows customizing the home directory path for users. This option is particularly useful when you want to specify a different location for a user’s home directory other than the default.

Here are several examples demonstrating how to use the -d option effectively:

Example 1: Create a user with a custom home directory path:
sudo useradd -d /home/engineer johndoe
This command creates a new user account named “johndoe” with the home directory set to /home/engineer.
Verification: Verify by listing the contents of /home directory to see if engineer directory exists.

Example 2: Specify a relative path for the home directory:
sudo useradd -d projects/johndoe johndoe
This command creates a user “johndoe” with the home directory located at /home/projects/johndoe.
Verification: Check the existence of /home/projects/johndoe.

Example 3: Use an absolute path outside of /home:
sudo useradd -d /data/users/johndoe johndoe
This command sets the home directory for “johndoe” to /data/users/johndoe.
Verification: Confirm /data/users/johndoe directory creation.

Example 4: Create a user with a home directory on a network mount:
sudo useradd -d /mnt/nfs/johndoe johndoe
This command assigns the home directory for “johndoe” to a network mount point at /mnt/nfs/johndoe.
Verification: Ensure /mnt/nfs/johndoe is accessible and mounted correctly.

Example 5: Set a specific home directory with symbolic links:
sudo useradd -d /home/links/johndoe johndoe
This command creates a user “johndoe” with a home directory linked to /home/links/johndoe.
Verification: Verify symbolic link integrity and permissions.

Example 6: Create a user without a home directory:
sudo useradd -M -d /nonexistent johndoe
This command adds “johndoe” with no home directory, useful for system accounts.
Verification: Check if the user “johndoe” exists without a home directory.

Example 7: Specify a home directory with special characters:
sudo useradd -d '/home/users & admins/johndoe' johndoe
This command sets the home directory for “johndoe” with spaces and an ampersand.
Verification: Ensure the directory /home/users & admins/johndoe is correctly created.

Example 8: Use environment variables in the home directory path:
sudo useradd -d $HOME/johndoe johndoe
This command sets the home directory path relative to the current user’s home directory.
Verification: Check if /home/current_user/johndoe directory exists after execution.

Example 9: Assign a nested directory structure as the home directory:
sudo useradd -d /home/developers/johndoe/projects johndoe
This command creates “johndoe” with a home directory path that includes a nested structure for projects.
Verification: Ensure the complete path /home/developers/johndoe/projects is valid.

Example 10: Create a user with an encrypted home directory:
sudo useradd -m -K ENCRYPT_METHOD=ecryptfs johndoe
This command sets up “johndoe” with an encrypted home directory using ecryptfs.
Verification: Verify encryption settings and home directory structure.

Tags: CommandsLinuxLinux Command TutorialLinux Commands
Previous Post

Adding Comments to New User Accounts in Linux

Next Post

How to Clone a Git Repository into a New Directory

Related You may like!

howto

How to Use -iname for Case-Insensitive Filename Searches in find

August 21, 2024
howto

Search for Files with Case-Insensitive Pattern Matching Using -ilname in find

August 21, 2024

Find Files by Group Name with -group in find Command

August 21, 2024

Locate Files by Group ID Using -gid in find Command

August 21, 2024

How to Search for Filesystems with -fstype in find Command

August 21, 2024

Use -false to Test Conditional Expressions in find Command

August 21, 2024
Next Post
howto

How to Clone a Git Repository into a New Directory

howto

Initializing and Reinitializing Git Repositories

howto

Adding Files to Git: A Complete Guide

Discussion about this post

Latest Updated

howto

How to Use -iname for Case-Insensitive Filename Searches in find

August 21, 2024
howto

Search for Files with Case-Insensitive Pattern Matching Using -ilname in find

August 21, 2024
howto

Find Files by Group Name with -group in find Command

August 21, 2024
howto

Locate Files by Group ID Using -gid in find Command

August 21, 2024
howto

How to Search for Filesystems with -fstype in find Command

August 21, 2024

Trending in Week

  • howto

    Using BTRFS Subvolume for User Home Directory in Linux

    22 shares
    Share 9 Tweet 6
  • Downloading Docker Images from a Registry

    13 shares
    Share 5 Tweet 3
  • Configuring SSL Connection Mode in mysqldump

    17 shares
    Share 7 Tweet 4
  • Omit Tablespace Information in mysqldump Output

    13 shares
    Share 5 Tweet 3
  • Setting MySQL Dump Compatibility Mode

    18 shares
    Share 7 Tweet 5
  • Setting Network Buffer Length in mysqldump

    13 shares
    Share 5 Tweet 3
  • Logging out from Docker Registries

    13 shares
    Share 5 Tweet 3
  • Scheduling Nodes in Kubernetes with kubectl uncordon

    12 shares
    Share 5 Tweet 3
  • Managing Default User Creation Settings in Linux

    15 shares
    Share 6 Tweet 4
  • Using Extended INSERT Syntax in mysqldump

    12 shares
    Share 5 Tweet 3
  • About Us
  • Privacy & Policy

© 2024 All Rights Reserved. Howto.swebtools.com.

No Result
View All Result

© 2024 All Rights Reserved. Howto.swebtools.com.