• 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

Using BTRFS Subvolume for User Home Directory in Linux

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

The useradd command in Linux is used to create a new user account. When combined with the --btrfs-subvolume-home option, it enables the creation of user home directories as BTRFS subvolumes. BTRFS (B-tree file system) is a modern filesystem with features like snapshots, subvolumes, and integrated RAID support, making it suitable for managing home directories efficiently.

Here are several examples demonstrating the usage of useradd with the --btrfs-subvolume-home option:

Example 1: Create a user with a BTRFS subvolume home directory.
sudo useradd --btrfs-subvolume-home john

This command creates a new user account named “john” and sets up its home directory as a BTRFS subvolume.

Verification Steps: After executing the command, verify by listing BTRFS subvolumes:
sudo btrfs subvolume list /home
Output should include a subvolume for the user “john”.

Example 2: Create a user with a specific BTRFS subvolume name.
sudo useradd --btrfs-subvolume-home --btrfs-subvolume-name=myhome jane

Here, a user “jane” is created with a custom-named BTRFS subvolume “myhome” for her home directory.

Verification Steps: Check the subvolume name:
sudo btrfs subvolume list /home
The output should show a subvolume named “myhome”.

Example 3: Specify additional options like user groups and comment.
sudo useradd --btrfs-subvolume-home --groups developers --comment "Developer Account" mike

This command creates a user “mike” belonging to the “developers” group, with a comment indicating its purpose.

Verification Steps: Ensure user details are correctly set:
id mike
Verify the groups and comments associated with the user.

Example 4: Set a specific shell for the user.
sudo useradd --btrfs-subvolume-home --shell /bin/bash sarah

Here, user “sarah” is created with the Bash shell.

Verification Steps: Check the user’s shell:
getent passwd sarah
Ensure the shell field (“/bin/bash”) is correctly set.

Example 5: Create a user with an expiration date.
sudo useradd --btrfs-subvolume-home --expiredate 2025-12-31 anna

This command creates a user “anna” whose account expires on December 31, 2025.

Verification Steps: Verify expiration date:
sudo chage -l anna
Check the “Account expires” field to ensure it reflects the set date.

Example 6: Assign a UID for the new user explicitly.
sudo useradd --btrfs-subvolume-home --uid 2001 tim

This command creates a user “tim” with a specific UID (2001).

Verification Steps: Verify UID assignment:
id tim
Check that the UID is correctly assigned to user “tim”.

Example 7: Create a user with a specified home directory path.
sudo useradd --btrfs-subvolume-home --home /mnt/data/users/emma emma

Here, user “emma” is created with a home directory located at /mnt/data/users/emma.

Verification Steps: Confirm the home directory path:
getent passwd emma
Check that the home directory field (“/mnt/data/users/emma”) is set correctly.

Example 8: Create a user with a specific default umask.
sudo useradd --btrfs-subvolume-home --create-home --user-group --umask 007 lucas

This command creates a user “lucas” with a default umask of 007, ensuring specific file permission settings.

Verification Steps: Verify umask configuration:
sudo su - lucas
Create a file to verify its permissions align with the umask set (e.g., touch testfile).

Example 9: Set a password for the new user upon creation.
sudo useradd --btrfs-subvolume-home --password $(openssl passwd -1 mypassword) max

Here, user “max” is created with the password “mypassword”.

Verification Steps: Attempt to log in as “max” using the set password to confirm login functionality.

Example 10: Create a system user without a home directory.
sudo useradd --btrfs-subvolume-home --system --no-create-home --shell /sbin/nologin service

This command creates a system user “service” without a home directory and with a restricted login shell.

Verification Steps: Check user details:
getent passwd service
Ensure the user “service” exists and has no home directory.

Tags: CommandsLinuxLinux Command TutorialLinux Commands
Next Post

Managing Default User Creation Settings in Linux

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

Managing Default User Creation Settings in Linux

howto

Setting Expiry Dates for User Accounts in Linux

howto

Configuring Password Inactivity Periods for Users in Linux

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.