4
3
I want to add a user named "nexus" with uid as 1234567 (example number) and gid 1234567.
I'm running the following command:
sudo useradd -r -U -u 1234567 -g 1234567 -m -c "nexus role account" -d /sonatype-work -s /bin/false nexus
But I get the error:
useradd: group '1234567' does not exist
And if I do:
sudo useradd -r -U -u 1234567 -m -c "nexus role account" -d /sonatype-work -s /bin/false nexus
Then when I check id -u nexus
it shows the correct uid
(1234567) but when I check id -g nexus
the gid
is set to 999
.
If I do sudo adduser --uid 1234567 nexus
then the user and group ids are set the same.
Can I do the same with useradd
or do I have to use adduser
to achieve my goal?
I've been following this tutorial btw:
http://www.tecmint.com/add-users-in-linux/
P.S.: If I have to use adduser
then can I do it without any human interaction; i.e.: automate the user creation via script?
EDIT:
This is the outcome of sudo adduser --uid 1234567 nexus
Adding user `nexus' ...
Adding new group `nexus' (1234567) ...
Adding new user `nexus' (1234567) with group `nexus' ...
The home directory `/home/nexus' already exists. Not copying from `/etc/skel'.
adduser: Warning: The home directory `/home/nexus' does not belong to the user you are currently creating.
Enter new UNIX password:
Retype new UNIX password:
No password supplied
Enter new UNIX password:
Retype new UNIX password:
No password supplied
Enter new UNIX password:
Retype new UNIX password:
No password supplied
passwd: Authentication token manipulation error
passwd: password unchanged
Try again? [y/N] n
Changing the user information for nexus
Enter the new value, or press ENTER for the default
Full Name []: Nexus
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
I think you need to do a
groupadd
first if you want to create a user with SPECIFIC uid AND gid. – Tom Yan – 2016-02-10T21:04:09.183I thought the
-U
would do that for me.. :S – Fadi – 2016-02-11T14:14:31.910