How to change the primary group of a user in Linux

Where necessary, you may need to have access to a VPS server so you can follow how to implement the steps in this article.  You can get a cheaper VPS Server from Contabo with 4vCPU cores, 8GM RAM, and 32TB Bandwidth for less than $5.50 per month. Get this deal here now

Table of Contents

Cloud VPS S

$5.50 Monthly
  • 4 vCPU Cores | 8GB RAM


$15.50 Monthly
  • 6 vCPU Cores | 16GB RAM


$17.50 Monthly
  • 8 vCPU Cores | 24GB RAM

In Linux, user accounts are organized into groups, which play a crucial role in managing permissions and access to resources. Each user has a primary group and can belong to multiple secondary groups. This article will guide you through the process of changing the primary group of a user in Linux.

Checking Current User Groups

Before making any changes, it’s essential to know the current group memberships of a user. The id command provides a quick overview, displaying the user’s UID (User ID), GID (Group ID), and group memberships.

id username

Replace “username” with the actual username of the user you’re interested in. This command will show you the user’s current primary group and any additional groups.

Listing Available Groups

To view a list of all available groups on your system, you can use the getent command in combination with the group database:

getent group

This command displays a list of all groups along with their GIDs. Review this list to choose the new primary group for the user.

Changing the Primary Group

The usermod command is used to modify user account details, including the primary group. To change the primary group of a user, use the following syntax:

sudo usermod -g new_primary_group username

Replace “new_primary_group” with the desired group name or GID, and “username” with the actual username. The sudo command is used to execute the usermod command with elevated privileges.

Verifying Changes

After changing the primary group, use the id command again to verify that the modifications were successful:

id username

Ensure that the “GID” corresponds to the new primary group.

Practical Example

Let’s consider an example where we change the primary group of the user “john” to the group “developers.”

sudo usermod -g developers john

After executing this command, you can verify the changes with:

id john

The output should reflect the updated primary group.

Hire us to handle what you want

Hire us through our Fiverr Profile and leave all the complicated & technical stuff to us. Here are some of the things we can do for you:

  • Website migration, troubleshooting, and maintenance.
  • Server & application deployment, scaling, troubleshooting, and maintenance
  • Deployment of Kubernetes, Docker, Cloudron, Ant Media, Apache, Nginx,  OpenVPN, cPanel, WHMCS, WordPress, and more
  • Everything you need on AWS, IBM Cloud, GCP, Azure, Oracle Cloud, Alibaba Cloud, Linode, Contabo, DigitalOcean, Ionos, Vultr, GoDaddy, HostGator, Namecheap, DreamHost, and more.

We will design, configure, deploy, or troubleshoot anything you want. Starting from $10, we will get your job done in the shortest time possible. Your payment is safe with Fiverr as we will only be paid once your project is completed.