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 OverflowFirst, 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.
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.
linux - User created with different UID and GID - Unix & Linux Stack Exchange
How do I create a new user with uid 4000 and shell /bin/csh to my linux system?
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.comCreate users on Multiple Machines with the Same UID
How do I find my user UID in Ubuntu?
How to add user with specific UID GID in Ubuntu?
What does UID 1000 mean?
Videos
First - UIDs less than 1000 are usually system reserved, pick a higher UID.
Second - Why are you wanting it to not have a home directory. Keep in mind the --no-create-home doesn't mean the user doesn't have a home directory assigned, it just isn't created. An error will be logged every time that user logs in.
Third - Please remember to post errors your get, else we can only assume as to what the problem is. I'm assuming it has to do with the name format, in which case, you can bypass this using --force-badname, as the error message would say, or use all lower case characters.
*edit typo
adduser command will let you include all the default home directories automatically. So you can not with adduser directly.
you can use useradd instead.
sudo useradd <username>
will create the user with the given user name.
While coming to UID , the Range 499 reserved for system users i.e in Linux each service creates its own user and below 499 UID will allocated for those users.
hope that helps.
Thanks to Tom Yan, I've ended up solving my issue by creating a group with the same name then added the user to that group. So I did the following:
sudo groupadd -r -g 1234567 nexus \
&& sudo useradd -r -u 1234567 -g 1234567 -m -c "nexus role account" -d /sonatype-work -s /bin/false nexus
Frankly, I think it's a bug(feature). The documentation indicates that you can use the '-U' option to simultaneously create the user and group at the same time. Intuitively you would think that in such a case, it would take the value from the '-g' flag and create the group accordingly.
[root@centos4]# useradd -U -u 200 -g 200 -m -d /home/ansible -s /usr/bin/bash ansible
useradd: group '200' does not exist
The example above is similar to your useradd command. However, if I simply remove the '-g 200' argument it works immediately. Although unfortunately it seems that the gid is allocated with the standard method.
[root@centos4]# useradd -U -u 200 -m -d /home/ansible -s /usr/bin/bash ansible
[root@centos4]# egrep ansible /etc/passwd
ansible:x:200:1000::/home/ansible:/usr/bin/bash
[root@centos4]# egrep ansible /etc/group
ansible:x:1000:
The answer to your question is that if you want to add user and group at the same time you have to remove the -g option. It's not as elegant as both you and I hoped, but its better than nothing.
Hope that helps. Take Care.
There are actually valid reasons for this. For instance, I used to work in a lab where we each had our own computer but our $HOME was in a shared drive exported by a server. So, my $HOME was
/users/terdon
Since the /users folder was actually not on my local machine but exported over NFS, for any analysis that was heavy on I/O, I would use data stored on my local hard drives so as not to burden the lab's network. To that end I, and everybody else, had two users: one that was system-wide and one that was local to the machine in question. The local user's home was
/home/localuser
However, I needed to have full access to my files whether I was logged in as terdon or as localuser and the way our sysadmin had implemented that was by giving both localuser and terdon the same UID. That way, I could freely manipulate my local files irrespective of which user I was currently logged in as.
The answer here is that Linux does not protect you from yourself.
If you really want to su root and go into the /etc files and give all the users the same UID, you can. It's just a text file.
But you really shouldn't and it will have unintended consequences.