• 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

Overriding Default Settings with Useradd Key-Value Pairs in Linux

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

When managing user accounts in Linux, the useradd command is essential for creating new users. The -K or --key KEY=VALUE option allows administrators to override default settings during user creation by specifying key-value pairs. This flexibility is particularly useful for tailoring user configurations to specific needs directly from the command line.

Here are several examples illustrating the use of the -K option with useradd:

Example 1: Setting User Home Directory
To create a new user john with a custom home directory:

    useradd -K HOME=/home/customhome john
    

This command sets the home directory of user john to /home/customhome.

Verification: Verify the user’s home directory using:

    grep john /etc/passwd
    

Example 2: Specifying User Shell
Creating a user mary with a specific shell (/bin/bash):

    useradd -K SHELL=/bin/bash mary
    

This assigns /bin/bash as the login shell for user mary.

Verification: Check the user’s shell setting:

    grep mary /etc/passwd
    

Example 3: Setting User UID
Assigning a custom UID (User ID) 1500 to user alex:

    useradd -K UID=1500 alex
    

This command sets the UID of user alex to 1500.

Verification: Ensure the UID is correctly applied:

    grep alex /etc/passwd
    

Example 4: Setting User Group
Adding user sarah to a secondary group developers:

    useradd -K GROUPS=developers sarah
    

This command adds user sarah to the developers group.

Verification: Confirm group membership:

    groups sarah
    

Example 5: Disabling User Login
Creating a system user serviceuser with login disabled:

    useradd -K LOGIN=0 serviceuser
    

This command prevents serviceuser from logging into the system.

Verification: Verify login status:

    grep serviceuser /etc/passwd
    

Example 6: Setting Account Expiry Date
Setting an expiry date (2025-12-31) for user peter:

    useradd -K EXPIRE=2025-12-31 peter
    

This command ensures user peter‘s account expires on December 31, 2025.

Verification: Check the expiry setting:

    chage -l peter
    

Example 7: Setting User Comment
Adding a comment ("John Doe, IT Support") for user jane:

    useradd -K COMMENT="John Doe, IT Support" jane
    

This adds a descriptive comment to user jane‘s account.

Verification: View the user’s comment field:

    grep jane /etc/passwd
    

Example 8: Specifying User Password
Setting an initial password for user guest (not recommended for production):

    useradd -K PASSWORD="password123" guest
    

This sets a non-encrypted password for user guest.

Verification: Attempt to login with the provided password.

Example 9: Setting User Default Group
Defining staff as the default group for user mark:

    useradd -K GROUP=staff mark
    

This makes staff the primary group for user mark.

Verification: Check the user’s primary group:

    id mark
    

Example 10: Customizing User GECOS Field
Setting a custom GECOS field ("Jane Doe,Developer,555-1234") for user dave:

    useradd -K GECOS="Jane Doe,Developer,555-1234" dave
    

This command customizes the general user information field for dave.

Verification: Verify the GECOS field contents:

    grep dave /etc/passwd
    
Tags: CommandsLinuxLinux Command TutorialLinux Commands
Previous Post

Using Custom Skeleton Directories for User Accounts in Linux

Next Post

Managing User Database Entries with Useradd 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

Managing User Database Entries with Useradd Command

howto

Creating Home Directories Automatically with Useradd Command

howto

Preventing Home Directory Creation 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.