How to Create User with UID and GID in Ubuntu? [3 Scenarios]

Linux-based systems are multiuser systems which means multiple users can operate on the same system. These users are identified by their unique UIDs(user identifiers), In Linux-based systems users are also assigned to a group with a specific GID(group identifier) when they are created. In this article, I’ll depict the approaches to create a user with UID and GID in Ubuntu.

What is UID in Ubuntu?

UID is the abbreviation for user identifier in Linux-based systems. UID depicts a unique number per user. It is primarily used to specify a user within the Linux system and which elements the user can work with. As with the user’s list, UIDs are also stored in the /etc/passwd file. In Ubuntu, like most other Linux distributions for new users, UID starts from 1000.

What is GID in Ubuntu?

GID is the abbreviation for group identifiers in Linux-based systems. GID depicts a unique number for a group of users who share some common entities. A user can belong to multiple groups so it can have multiple GIDs. As with the user’s list & UIDs, GIDs are also stored in the /etc/passwd file. In Ubuntu, like most other Linux distributions for new groups, GID starts from 1000.

Watch 3 Scenarios to Create User with UID and GID in Ubuntu

Summary

You can create a new user in Ubuntu with a specific UID or a specific GID or both specific UID & GID. Now, To do any of that you can follow the below-stated specific case:

Case 01: Creating a User With Specific UID in Ubuntu

  • Create a new user with a specific UID using the useradd command and the -u option in Ubuntu.
  • Verify the UID of the newly created user using the id command.

Case 02: Creating a User With Specific GID in Ubuntu

  • First, Create a group with the specific GID you want using the groupadd command and the -g option in Ubuntu.
  • Next, Verify the GID of the newly created group.
  • After that, Add a new user with the specific GID using the useradd command and the -g option in Ubuntu.
  • Finally, Verify the GID of the newly created user using the id command with the -g option.

Case 03: Creating a User With Specific UID & GID in Ubuntu

  • First, Create a group with the specific GID you want using the groupadd command and the -g option in Ubuntu.
  • Next, Verify the GID of the newly created group.
  • Then, Add a new user with a specific UID & the specific GID using the useradd command with the -u option(for UID) and the -g option(for GID) in Ubuntu.
  • Finally, Verify the UID & GID of the newly created user using the id command.

A.  Creating a User With a Specific UID in Ubuntu

In the following example, I will create a new user named “rick” with a specific UID 2013. I have illustrated the full process in the following 2 steps.

Step 01: Create a New User With a Specific UID in Ubuntu

You can create a new user with your desired UID from the terminal using the useradd command. However, You have to be a root user to execute the useradd command. You can easily do this by prefixing the sudo command and then providing the user password. Type the following command in the Ubuntu terminal.

sudo useradd -u 2013 rick

In the following image, you can see that I have created a new user named “rick”.Creating user with specific UID using the useradd command in Ubuntu.Now, to be capable of logging into the newly created user “rick”, you need to set a password for the user by typing the following command:

sudo passwd rick

After running the above command, you’ll be able to set a password for the newly created user like the following image. Moreover, now you can now log into the new user “rick” whenever you want.Setting password for the new user.

Step 02: Confirm Whether the User Contains the Specific UID

You can check whether the new user “rick” contains the assigned UID:2013 by typing the following command.

id rick

In the following image, you can see that the new user “rick” has been assigned with the desired UID 2013.Checking the UID and GID of the newly created user in Ubuntu.

NB: By default, a newly created user contains the GID same as the UID if not specified.


B.  Creating a User With a Specific GID in Ubuntu

In the following example, I will create a new user named “morty” with a specific GID 2023. I have illustrated the full process in the following 4 steps.

Step 01: Create a Group with a Specific GID in Ubuntu

You can create a new group with your desired GID from the terminal using the groupadd command. However, You have to be a root user to execute the groupadd command. You can easily do this by prefixing the sudo command and then providing the user password.

Here, I have created a group named “mortygroup” with GID 2023. To do so Type the following command in the Ubuntu terminal.

sudo groupadd -g 2023 mortygroup

In the following image, you can see that I have created a new group named “mortygroup”.Creating a new group with specific GID using the groupadd command in Ubuntu.

Step 02: Confirm Whether the Group Contains the Specific GID

You can check whether the new group “mortygroup” contains the assigned GID:2023 by typing the following command.

getent group | grep mortygroup

In the following image, you can see that the new group “mortygroup” has been assigned with the desired GID 2023.Checking the GID of the newly created group.

Step 03: Create a New User With a Specific GID in Ubuntu

Now, create a new user with your desired GID from the terminal using the useradd command with the -g option followed by the desired GID. However, You have to be a root user to execute the useradd command. You can easily do this by prefixing the sudo command and then providing the user password. Type the following command in the Ubuntu terminal.

sudo useradd -g 2023 morty

In the following image, you can see that I have created a new user named “morty”.Creating the new user with the desired GID.Now, to be capable of logging into the newly created user “morty”, you need to set a password for the user by typing the following command:

sudo passwd morty

After running the above command, you’ll be able to set a password for the newly created user like the following image. Moreover, now you can now log into the new user “morty” whenever you want.Setting password for the newly created user.



Step 04: Confirm Whether the User Contains the Desired GID

You can check whether the new user “morty” contains the assigned GID:2023 by typing the following command.

id -g morty

In the following image, you can see that I have created the new user “morty” with our desired GID 2023.Checking the GID of the newly created user using the id command.

C. Creating a User With Both Specific UID & GID in Ubuntu

In the following example, I will create a new user named “rickmorty” with a specific UID(2050) & GID(2060). I have illustrated the full process in the following 4 steps.

Step 01: Create a Group with a Specific GID

You can create a new group with your desired GID from the terminal using the groupadd command. However, You have to be a root user to execute the groupadd command. You can easily do it by prefixing the sudo command and then providing the user password.

Here, I have created a group named “rmgroup” with GID 2060. To do so Type the following command in the Ubuntu terminal.

sudo groupadd -g 2060 rmgroup

In the following image, you can see that I have created a new group named “rmgroup”.Creating a group with a specific GID 2060 using the groupadd command in Ubuntu.

Step 02: Confirm Whether the Group Contains the Specific GID

You can check whether the new group “rmgroup” contains the assigned GID:2060 by typing the following command.

getent group | grep rmgroup

In the following image, you can see that I have created the new group “rmgroup” with the desired GID 2060.Checking the GID of the newly created group.

Step 03: Create a New User With the Specific UID & GID in Ubuntu

Now, to create user with UID and GID from the terminal using the useradd command with the -u option followed by the desired UID and with the -g option followed by the desired GID. However, You have to be a root user to execute the useradd command. You can easily do it by prefixing the sudo command and then providing the user password. Type the following command in the Ubuntu terminal.

sudo useradd -u 2050 -g 2060 rickmorty

In the following image, you can see that I have created a new user named “rickmorty”.Creating user with UID and GID in Ubuntu.Now, to be capable of logging into the newly created user “rickmorty”, you need to set a password for the user by typing the following command:

sudo passwd rickmorty

After running the above command, you’ll be able to set a password for the newly created user like the following image. Moreover, now you can now log into the new user “rickmorty” whenever you want.Setting password for the newly created user.



Step 04: Confirm Whether the User Contains the Desired GID

You can check whether the new user “rickmorty” contains the assigned UID:2050 & GID:2060 by typing the following command.

id rickmorty

In the following image, you can see that the I have created new user “rickmorty” with our desired UID:2050 & GID:2060.Checking the UID and GID of the newly created user using the id command in ubuntu.

Conclusion

In Linux-based multiuser systems UIDs and GIDs play an important role in maintaining the harmony of the system resource distributions among multiple users and groups. Hope this article will help you to play with the approaches to create a user with custom UID and GID in Ubuntu.

People Also Ask

What is UID & GID?

In Linux-based systems, UID(user identifier) depicts a unique number per user. It is primarily used to specify a user within the Linux system and which elements the user can work with. Similarly, GID(group identifier) depicts a unique number for a group of users who share some common entities.

What is the difference between UID and GID?

In Linux-based systems, UID(user identifier) depicts a unique number per user which defines a user within the Linux system and which elements the user can work with. On the other hand, GID(group identifier) depicts a unique number for a group of users who share some common entities. Another important difference is that a unique UID is represented by a single user only however, multiple users can represent a unique GID.

Can GID and UID be the same?

Yes, they can be the same. To be honest, when we’re creating regular users in Linux-based systems by default UID and GID are the same numbers.

What does UID 1000 mean?

In Linux-based systems, UID starts from 1000. Henceforth, when you create a new user for the first time by default the system assigns the user with UID 1000.

What does GID 1000 mean?

In Linux-based systems, GID starts from 1000. Henceforth, when you create a new user for the first time by default the system assigns the user to a group with GID 1000.

How do I find my user UID in Ubuntu?

UIDs are stored in the same /etc/passwd file as the user’s list in Linux. Therefore you can check that file or simply run the following command “id USERNAME” to get your user’s UID.

How do I find my user GID in Ubuntu?

GIDs are stored in the same /etc/passwd file as the user’s list in Linux. Therefore you can check that file or simply run the following command “id USERNAME” to get your user’s GID.

How to set UID in Linux?

In Linux, You can set a new UID of a user by using the usermod command. To change your user’s UID to XXXX you can run the following command “usermod -u XXXX USERNAME

How to set GID in Linux?

In Linux, You can set a new UID of a user by using the groupmod command. To change the GID of a group of your user to XXXX you can run the following command “groupmod -g XXXX GROUPNAME”.

What are the UID and GID of the root?

The root user is the supreme one among all users in the Linux system. Moreover, the root user can exercise all kinds of special powers in a Linux-based system. In Linux, the root user is assigned to UID 0 and GID 0. To conclude, It is not the naming that makes it supreme but this special UID and GID.

Relaed Articles

Rate this post
Md. Ashakul Islam Sowad

Md. Ashakul Islam Sowad

Hi, I am Md. Ashakul Islam Sowad from Dhaka, Bangladesh. I have completed my undergraduate degree in Biomedical Engineering from the Bangladesh University of Engineering and Technology (BUET). I love to watch football and play video games in my free time. Here, I am working as a Linux Content Developer Executive. Furthermore, as a Linux enthusiast, I am always learning new things about Linux-based systems and I’ll be sharing them here. Read Full Bio

We will be happy to hear your thoughts

Leave a reply

LinuxSimply
Logo