• 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

Creating User Groups Automatically with Useradd Command

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

The useradd command in Unix-like operating systems is used to create new user accounts. One of the options available with this command is -U or --user-group. This option instructs useradd to create a new group with the same name as the user, and add the user to this group by default. This is particularly useful for ensuring that each user has their own dedicated group without the need for manual group creation.

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

Example 1: Creating a user ‘john’ and automatically creating a group ‘john’.

    $ sudo useradd -U john
    

Output: No output indicates success. To verify, check the existence of user ‘john’ and group ‘john’.

Example 2: Creating a user ‘alice’ and automatically creating a group ‘alice’.

    $ sudo useradd -U alice
    

Output: No output on success. Verify by checking user ‘alice’ and group ‘alice’.

Example 3: Creating a user ‘mark’ with the --user-group option.

    $ sudo useradd --user-group mark
    

Output: No output if successful. Check user ‘mark’ and group ‘mark’ for verification.

Example 4: Specifying additional options while using -U, such as setting a home directory.

    $ sudo useradd -U -d /home/sam sam
    

Output: No output upon success. Verify the user ‘sam’ and group ‘sam’ existence.

Example 5: Creating a user ‘testuser’ with a specified UID and automatically creating group ‘testuser’.

    $ sudo useradd -U -u 2001 testuser
    

Output: No output if successful. Verify the presence of ‘testuser’ and its corresponding group.

Example 6: Creating a user ‘demo’ with -U and specifying a different shell.

    $ sudo useradd -U -s /bin/bash demo
    

Output: No output if user ‘demo’ and group ‘demo’ are created successfully. Verify both ‘demo’ user and group.

Example 7: Creating a user ‘backup’ with -U and specifying supplementary groups.

    $ sudo useradd -U -G adm,users backup
    

Output: No output upon success. Verify user ‘backup’ and its supplementary groups ‘adm’ and ‘users’.

Example 8: Creating a user ‘newuser’ with -U and specifying a comment.

    $ sudo useradd -U -c "New User Account" newuser
    

Output: No output if the command executes successfully. Verify user ‘newuser’ and its corresponding group.

Example 9: Creating a user ‘dev’ with -U and specifying an expiration date.

    $ sudo useradd -U -e 2025-12-31 dev
    

Output: No output if successful. Verify the presence of ‘dev’ user and ‘dev’ group before the expiration date.

Example 10: Creating a user ‘webadmin’ with -U and setting a password expiry date.

    $ sudo useradd -U -f 30 webadmin
    

Output: No output upon success. Verify user ‘webadmin’ and ‘webadmin’ group for the changes.

Tags: CommandsLinuxLinux Command TutorialLinux Commands
Previous Post

Assigning User IDs (UIDs) for User Accounts Command

Next Post

Using SEUSER for SELinux User Mapping 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

Using SEUSER for SELinux User Mapping with Useradd Command

howto

Managing User Accounts with Extra Users Database Command

howto

How to Exclude Bad Names when Creating User Accounts 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.