First, create the group if it doesn't exist:

$ groupadd -g 4200 sysadmin2

Next, create the user and add it to the group:

$ useradd sysadmin2 -u 4201 -g 4200 -m -s /bin/bash
$ useradd appadmin1 -u 4100 -g 4100 -m -s /bin/bash 

-m creates a home directory if it does not exist, and -s sets the user login shell path.

Don't forget to reset password for each user.

Answer from Max on Stack Overflow
Top answer
1 of 3
78

First, create the group if it doesn't exist:

$ groupadd -g 4200 sysadmin2

Next, create the user and add it to the group:

$ useradd sysadmin2 -u 4201 -g 4200 -m -s /bin/bash
$ useradd appadmin1 -u 4100 -g 4100 -m -s /bin/bash 

-m creates a home directory if it does not exist, and -s sets the user login shell path.

Don't forget to reset password for each user.

2 of 3
14

In summary and in general, you can use the useradd command to add users to a linux system. The -u flag allows you to set a specific user id and the -g flag allows you to set a specific group id. Please see useradd's manpage for more details -- on a terminal, type man useradd to see it.

Now, specifically about your problem, see below.

Assumming you have three groups on your original machine:

$ cat /etc/group
...
appadmins:x:4100:
sysadmins:x:4200:
dataadmins:x:4300:
...

On your destination/new machine, you should first create the groups using:

groupadd appadmins -g4100
groupadd sysadmins -g4200
groupadd dataadmins -g4300

Then, you can proceed to create the actual users like so:

useradd appadmin1 -u4100 -g4100 -d/home/appadmin1 -s/bin/bash
useradd appadmin2 -u4101 -g4100 -d/home/appadmin1 -s/bin/bash
useradd sysadmin1 -u4200 -g4200 -d/home/sysadmin1 -s/bin/bash
useradd sysadmin2 -u4201 -g4200 -d/home/sysadmin2 -s/bin/bash
useradd dataadmin1 -u4300 -g4300 -d/home/dataadmin1 -s/bin/bash
useradd dataadmin2 -u4301 -g4300 -d/home/dataadmin2 -s/bin/bash

The -d option is used to set the home directory and the -s option is used to set the shell. Again, -u and -g are used to set a specific user and group id.

To check that everything went correctly, just use grep admin on your /etc/passwd file:

$ grep admin /etc/passwd
appadmin1:x:4100:4100::/home/appadmin1:/bin/bash
appadmin2:x:4101:4100::/home/appadmin1:/bin/bash
sysadmin1:x:4200:4200::/home/sysadmin1:/bin/bash
sysadmin2:x:4201:4200::/home/sysadmin2:/bin/bash
dataadmin1:x:4300:4300::/home/dataadmin1:/bin/bash
dataadmin2:x:4301:4300::/home/dataadmin2:/bin/bash

If something is wrong, you can use userdel or groupdel accordingly and start over.

🌐
Linuxize
linuxize.com › home › linux commands › how to create users in linux (useradd command)
How to Create Users in Linux (useradd Command) | Linuxize
March 10, 2026 - By default, when a new user is created, the system assigns the next available UID from the range of user IDs specified in the login.defs file. Invoke the useradd command with the -u (--uid) option to create a user with a specific UID.
Discussions

linux - User created with different UID and GID - Unix & Linux Stack Exchange
I'm creating a new user in my system, by calling: sudo useradd -m -G nas -s /bin/bash alf which supposedly should create a new user with the same UID and GID. However the passwd file is appended w... More on unix.stackexchange.com
🌐 unix.stackexchange.com
How do I create a new user with uid 4000 and shell /bin/csh to my linux system?
Read the adduser man page. More on reddit.com
🌐 r/linuxquestions
11
1
September 20, 2022
Creating users and groups with set UID/GID

If you ssh into your system you can use non-Synology specific linux tools to create users and assign UIDs and GIDs. I've done it (I'll have to dig up my notes) and I barely understand what I'm doing.

More on reddit.com
🌐 r/synology
3
5
March 16, 2019
Create users on Multiple Machines with the Same UID
You might consider reframing the problem. Don't try to keep local accounts in sync across multiple hosts, use a central directory. Since you're already on RHEL, then FreeIPA or Red Hat Directory Server should be a good fit. More on reddit.com
🌐 r/ansible
9
1
May 21, 2021
People also ask

How do I find my user UID in Ubuntu?
To find your user UID, simply run: id -u User_Name. UIDs are stored in the same /etc/passwd file as the user's list in Linux. You can also check this file to get your UID.
🌐
linuxsimply.com
linuxsimply.com › home › how to create user with uid and gid in ubuntu? [3 cases]
How to Create User with UID and GID in Ubuntu? [3 Cases]
How to add user with specific UID GID in Ubuntu?
To add user with specific UID and GID in Ubuntu, first create a group with the specific GID: sudo groupadd -g . Then create a user with that GID and your specific UID: sudo useradd -u -g .
🌐
linuxsimply.com
linuxsimply.com › home › how to create user with uid and gid in ubuntu? [3 cases]
How to Create User with UID and GID in Ubuntu? [3 Cases]
What does UID 1000 mean?
UID 1000 usually stands for user identifier 1000. In Unix-based systems, every user is given a unique identifier for identification. Usually, UID 1000 is the default number assigned to the initial user created on a system. This number is important for managing the system and setting the file permissions.
🌐
linuxsimply.com
linuxsimply.com › home › how to create user with uid and gid in ubuntu? [3 cases]
How to Create User with UID and GID in Ubuntu? [3 Cases]
🌐
MonoVM
monovm.com › blog › server › how to create user in linux [linux create user command]
How to Create User in Linux [Linux Create User Command]
March 5, 2023 - Now, -g (- -gid) helps create a user with a certain login group. You have to mention the GID number or the group name. ... As you know, the users are known by their respective UID and username. When we talk about a User Identifier, UID, it is simply a positive integer that is allocated to every user in the Linux system.
🌐
Cherry Servers
cherryservers.com › home › blog › linux › how to create a user in linux [with examples]
How to Create a User in Linux [With Examples]
April 16, 2026 - The -u (--uid) option allows you to define a specific User ID for the user. For example, to create a user called bob with a UID of 1005, run the command:
🌐
LinuxSimply
linuxsimply.com › home › how to create user with uid and gid in ubuntu? [3 cases]
How to Create User with UID and GID in Ubuntu? [3 Cases]
April 1, 2024 - Create a new user with specific UID and GID: Run sudo useradd -u <YYYY> -g <XXXX> <USERNAME>. Confirm the user’s desired UID and GID: Run id <USERNAME>. In this article, I will elaborately discuss the abovementioned steps along with two more cases.
Find elsewhere
🌐
StrongDM
strongdm.com › blog › security
How to Create Users in Linux with useradd (Step-by-Step)
February 24, 2025 - This command displays the user ID, group ID, and group memberships associated with your newly created user. You can customize how you create new users in Linux with the useradd command in various ways.
🌐
ITzGeek
itzgeek.com › home › how to's › linux › how to create users in linux using useradd / adduser command
How To Create Users in Linux Using useradd / adduser Command
April 23, 2019 - By default, whenever the user is created in Linux, the system assigns the next available UID from the range of user IDs between UID_MIN and UID_MAX in the /etc/login.defs file. Use the -u option to create a user with a specific UID.
🌐
Red Hat
redhat.com › en › blog › user-account-gid-uid
Linux sysadmin basics: User account management with UIDs and GIDs
November 20, 2025 - As a Linux administrator for more than 20 years, I've never personally run out of those first 999 system account numbers. The root account has the awesome privilege of having UID = 0 and GID = 0. These numbers are what give the root account its overwhelming power. If you don't believe me, rename the root account to goonygoogoo, or whatever you choose, and then create a new user account named root, allowing the system to assign the next available UID and GID to it.
🌐
Ubuntu Shell
ubuntushell.com › create-users-in-linux
How to Create Users in Linux using "useradd" Command [10 Practical Examples]
February 22, 2022 - Instead of new, if you want to ... newly created user, then use the -d flag along with the useradd command as below. ... View the /etc/passwd to verify the path is attached or not to the new user, as shown below.
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_enterprise_linux › 6 › html › deployment_guide › s2-users-cl-tools
3.4. Managing Users via Command-Line Tools | Deployment Guide | Red Hat Enterprise Linux | 6 | Red Hat Documentation
The useradd utility creates new users and adds them to the system. Following the short procedure below, you will create a default user account with its UID, automatically create a home directory where default user settings will be stored, /home/username/, and set the default shell to /bin/bash.
🌐
Warp
warp.dev › terminus by warp › linux › create user in linux
How To Create And Configure A New User In Linux | Warp
March 5, 2024 - By default, the users created using the useradd command are automatically assigned an unused UID and GID by the system. To create a new user with an arbitrary UID, you can use the -u flag (short for --uid ) as follows:
Top answer
1 of 1
10

Method 1 - If you just want to create a user with a given UID

  1. Install Ubuntu normally
  2. Log into Ubuntu
  3. Open a Terminal
  4. Create a new user with the ID 1200 sudo adduser -u 1200 <username>
  5. Confirm that the user was created with the desired id awk -F: '/\/home/ {printf "%s:%s\n",$1,$3}' /etc/passwd
  6. Add the newly created user to the sudoers group sudo adduser <username> sudo
  7. Logout
  8. Login with the newly created user
  9. (optional) Delete the old user

Method 2 - Automated Ubuntu installation using preseeding

In order to be able to define a UID range at installation time, you need to automate the Ubuntu installation using preseeding, which is basically

a way to to set answers to questions asked during the installation process, without having to manually enter the answers while the installation is running. This makes it possible to fully automate most types of installation and even offers some features not available during normal installations.

Using this method, which is way to extensive to be posted as part of this post, you can (amongst many other things) setup the account which will created at installation time. Example:

# Skip creation of a root account (normal user account will be able to
# use sudo). The default is false; preseed this to true if you want to set
# a root password.
#d-i passwd/root-login boolean false
# Alternatively, to skip creation of a normal user account.
#d-i passwd/make-user boolean false

# Root password, either in clear text
#d-i passwd/root-password password r00tme
#d-i passwd/root-password-again password r00tme
# or encrypted using an MD5 hash.
#d-i passwd/root-password-crypted password [MD5 hash]

# To create a normal user account.
#d-i passwd/user-fullname string Ubuntu User
#d-i passwd/username string ubuntu
# Normal user's password, either in clear text
#d-i passwd/user-password password insecure
#d-i passwd/user-password-again password insecure
# or encrypted using an MD5 hash.
#d-i passwd/user-password-crypted password [MD5 hash]
# Create the first user with the specified UID instead of the default.
#d-i passwd/user-uid string 1010
# The installer will warn about weak passwords. If you are sure you know
# what you're doing and want to override it, uncomment this.
#d-i user-setup/allow-password-weak boolean true

# The user account will be added to some standard initial groups. To
# override that, use this.
#d-i passwd/user-default-groups string audio cdrom video

# Set to true if you want to encrypt the first user's home directory.
d-i user-setup/encrypt-home boolean false

Notice the line:

# Create the first user with the specified UID instead of the default.
d-i passwd/user-uid string 1010

If you want to learn more about automated installations there are several sources of useful information in the Internet. This is the official documentation currently:

https://help.ubuntu.com/lts/installation-guide/armhf/apbs01.html

🌐
TecMint
tecmint.com › home › linux commands › how to create users in linux [15 useradd command examples]
15 Useful Useradd Commands with Examples in Linux
November 23, 2023 - However, this behavior can be changed by using the '-d' option along with the location of the new home directory (e.g., ‘/data/projects‘). For instance, the following command will create a user ‘anusha‘ with a home directory set to ‘/data/projects‘. # useradd -d /data/projects anusha # passwd anusha · You can view the user’s home directory and other user-related information, such as user ID, group ID, shell, and comments using the following cat command. cat /etc/passwd | grep anusha anusha:x:1001:1001::/data/projects:/bin/bash ... In Linux, every user has their own UID (Unique Identification Number).
🌐
Linux Manual Page
linux.die.net › sag › adduser.html
11.2. Creating a user
On most systems it doesn't matter what the numeric user and group ids are, but if you use the Network filesystem (NFS), you need to have the same uid and gid on all systems. This is because NFS also identifies users with the numeric uids. If you aren't using NFS, you can let your account creation tool pick them automatically.
🌐
Linux Man Pages
linux.die.net › man › 8 › useradd
useradd(8) - Linux man page
When invoked without the -D option, the useradd command creates a new user account using the values specified on the command line plus the default values from the system.