0

I reciently decided to manage my own web server (Ubuntu/Nginx) and as best practices I went and disabled the root user and created a new one with root privileges. When I created the new user I didn't specify what group to add it to, this is how I created it.

adduser newUserName

Then I added to the sudo group

gpasswd -a newUserName sudo

What confuses me is that when I type cat /etc/group to see all groups there is a group with the name of the user I created.

root
...
newUserName

So I started wondering if the way I created the new user is the right way to do it or it's better to create a group first and then add any user with the same privileges to the same group.

  • Can someone suggest a best practice to manage users/groups in Ubuntu Server or direct me to where I can find more information?

  • What would happen if I create a new group with the same privileges as the existing user and move the existing user newUserName to this folder?

I guess I'm looking to have a better understanding of how users are typically managed in Ubuntu Server.

Thanks a lot.

3

useradd / usermod command have an option to specify the primary group( -g). If you create a user without -g option a primarygroup will be created with the same name as the new username and the new user will be added to this group. When user creates a file/directory it gets the group of user's primary group. You can have only one primary group assigned to a user. But you can have multiple secondary groups per user. Use option -G with useradd / usermod command to add secondary groups.

So if you want to create a user and with primary group as sudo , use command:

useradd -g sudo <newusername>

useradd syntax:

useradd -g <primary group> -G <secondarygroup1>,<secondarygroup2> <NewUsername> 

In linux the primary group will stored to /etc/passwd file. /etc/groups file will have only list of secondary groups of a user, so getent group sudo ( which looks in /etc/group for group info) won't show the primary group of that user ie. sudo . Use id <username> or groups <Username> to list all the groups, the user is member of. You can also check the 4th field of the /etc/passwd for the primary group gid of a user.

Google and Man pages are your best friend when in doubt.

| improve this answer | |
  • I just tried adding a couple of new users using useradd -g sudo <newusername> and they show when I show all users cut -d: -f1 /etc/passwd but why aren't they listed as members of the sudo folder when I type getent group sudo? They are not listed as folders either. Can you please elaborate on this. – fs_tigre Jun 24 '15 at 15:07
  • I didn't get what you mean by sudo folder? You mean sudo group? – jijinp Jun 25 '15 at 7:43
  • 1
    I hope the new info added to the answer will help you. – jijinp Jun 25 '15 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.