How to Automatically Add New Users to Custom Groups

Is there a way in Rocky/RHEL/CentOS to automatically add new users to a custom groups?
Ubuntu has the /etc/adduser.conf file that can do this. I think it might be possible with /etc/default/useradd but that is unclear to me.

I asked this on the r/linuxadmin subreddit as well and no one knew of a native way to do this.

It does look like because in the man page of useradd I see this.

Default values for account creation.
-g, --gid GROUP

The group name or ID for a new user’s initial group (when the -N/–no-user-group is used or when the USERGROUPS_ENAB variable is set to no in /etc/login.defs). The named group must exist, and a numerical group ID must have an existing entry.

This option sets the GROUP variable in /etc/default/useradd.

I have never used it though since I use Ansible for usermanagement now days.

Thank you. I saw that as well but we want to still create the user-group. We decided we are just going to have to enforce Ansible usage. .

1 Like