• 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

Setting Prefix Directories for Useradd Command

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

The useradd command in Linux is used to create new user accounts. One of its options, -P or --prefix PREFIX_DIR, allows setting a prefix directory where user home directories will be created. This is particularly useful when you want to organize user home directories under a specific directory structure.

Here are several examples demonstrating the usage of -P option with useradd:

Example 1: Setting the prefix directory to /home/users:

            useradd -P /home/users john
        

This command creates a new user john and sets their home directory to /home/users/john.

Example 2: Using an existing directory path:

            useradd -P /srv/users alice
        

This command creates a user alice with the home directory at /srv/users/alice.

Example 3: Specifying a relative path:

            useradd -P relative/path bob
        

Here, the command creates a user bob with the home directory at relative/path/bob.

Example 4: Using an environment variable:

            useradd -P $HOME/users charlie
        

This command creates a user charlie with the home directory at $HOME/users/charlie.

Example 5: Combining options with user creation:

            useradd -m -P /var/lib/users dave
        

Here, -m ensures creation of the user’s home directory and -P sets it to /var/lib/users/dave.

Verification: To verify if the user creation with the specified prefix directory was successful, you can check the existence of the user’s home directory using:

            ls -ld /path/to/prefix/directory/username
        

Replace /path/to/prefix/directory/username with the actual path where the user’s home directory should have been created.

Tags: CommandsLinuxLinux Command TutorialLinux Commands
Previous Post

Using Chroot Directories with Useradd Command

Next Post

Specifying Login Shells for User Accounts Command

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

Specifying Login Shells for User Accounts Command

howto

Assigning User IDs (UIDs) for User Accounts Command

howto

Creating User Groups Automatically with Useradd Command

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.