• 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

Assigning Primary Group for New User Accounts in Linux

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

When adding new user accounts in Linux using the useradd command, administrators can specify various options to customize user attributes. One crucial option is -g (or --gid), which allows assigning a primary group to the new user. This group determines the default group ownership of files created by the user.

Here are several examples demonstrating how to use useradd with the -g option:

Example 1: Assigning the group “staff” to a new user “john”:

    useradd -g staff john
    

This command creates a new user account named “john” with the primary group set to “staff”. To verify, use:

    id john
    

Output should include “staff” as the primary group.

Example 2: Assigning a numerical group ID (GID) directly:

    useradd -g 1002 sarah
    

This command assigns the group with GID 1002 to the new user “sarah”. Verify using:

    id sarah
    

Output should show the group associated with GID 1002.

Example 3: Specifying an existing group by name and creating a new user:

    useradd -g developers alice
    

Here, “alice” is added with the primary group “developers”. Verify with:

    id alice
    

Example 4: Creating a user without specifying a primary group (defaults to user’s name as group):

    useradd charlie
    

Check the primary group assignment for “charlie” using:

    id charlie
    

Example 5: Using the --gid long option:

    useradd --gid managers dave
    

This assigns the group “managers” to the user “dave”. Verify the group association with:

    id dave
    

Each of these commands utilizes the useradd utility with the -g option to manage the primary group assignment for new user accounts in Linux. Verifying the results involves checking the output of id username where “username” is the newly created user to confirm the group association.

Tags: CommandsLinuxLinux Command TutorialLinux Commands
Previous Post

Configuring Password Inactivity Periods for Users in Linux

Next Post

Adding Supplementary Groups to User Accounts 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

Adding Supplementary Groups to User Accounts in Linux

howto

Using Custom Skeleton Directories for User Accounts in Linux

howto

Overriding Default Settings with Useradd Key-Value Pairs 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.