Restoring default groups in Ubuntu

Sometimes it happen that user messes up with the groups of its user account while trying adding or removing some group or doing something which indirectly affect them. Ubuntu provides following command to add user to the group:
usermod -G group1,group2,... user
The default action of the command is that the user is added to the specified groups but removed from all other groups. -a parameter is needed to be given to append the group instead of replacing.
It is one of the most common lapse from user and they ended up with their sudoer account not able access many of the resources.

The solution to this is to find out the default groups and then adding them explicitly. One can ask someone who has unmodified groups the list of groups his account is added to.
groups gives the list of groups to which the current user is added.

Instead the user can also view the default groups without needing others help. There exists a log file which is created at the time of installation containing the log of processes it has gone through. The addition of user to different groups is definitely one of the process. The path of file is /var/log/installer/syslog.
Just view the log output which contain user-setup as a substring.
cat /var/log/installer/syslog | grep user-setup

The output comes as
Jun 29 22:35:54 ubuntu user-setup: pwconv: failed to change the mode of /etc/passwd- to 0600
Jun 29 22:35:54 ubuntu user-setup: Shadow passwords are now on.
Jun 29 22:35:55 ubuntu user-setup: Adding user `userabc' ...
Jun 29 22:35:55 ubuntu user-setup: Adding new group `userabc' (1000) ...
Jun 29 22:35:55 ubuntu user-setup: Adding new user `userabc' (1000) with group `userabc' ...
Jun 29 22:35:55 ubuntu user-setup: Creating home directory `/home/userabc' ...
Jun 29 22:35:55 ubuntu user-setup: Copying files from `/etc/skel' ...
Jun 29 22:35:57 ubuntu user-setup: addgroup: The group `lpadmin' already exists as a system group. Exiting.
Jun 29 22:35:57 ubuntu user-setup: Adding group `sambashare' (GID 124) ...
Jun 29 22:35:57 ubuntu user-setup: Done.
Jun 29 22:35:57 ubuntu user-setup: Adding user `userabc' to group `adm' ...
Jun 29 22:35:57 ubuntu user-setup: Adding user userabc to group adm
Jun 29 22:35:57 ubuntu user-setup: Done.
Jun 29 22:35:57 ubuntu user-setup: Adding user `userabc' to group `cdrom' ...
Jun 29 22:35:57 ubuntu user-setup: Adding user userabc to group cdrom
Jun 29 22:35:57 ubuntu user-setup: Done.
Jun 29 22:35:57 ubuntu user-setup: Adding user `userabc' to group `dip' ...
Jun 29 22:35:57 ubuntu user-setup: Adding user userabc to group dip
Jun 29 22:35:58 ubuntu user-setup: Done.
Jun 29 22:35:58 ubuntu user-setup: Adding user `userabc' to group `lpadmin' ...
Jun 29 22:35:58 ubuntu user-setup: Adding user userabc to group lpadmin
Jun 29 22:35:58 ubuntu user-setup: Done.
Jun 29 22:35:58 ubuntu user-setup: Adding user `userabc' to group `plugdev' ...
Jun 29 22:35:58 ubuntu user-setup: Adding user userabc to group plugdev
Jun 29 22:35:58 ubuntu user-setup: Done.
Jun 29 22:35:58 ubuntu user-setup: Adding user `userabc' to group `sambashare' ...
Jun 29 22:35:58 ubuntu user-setup: Adding user userabc to group sambashare
Jun 29 22:35:58 ubuntu user-setup: Done.
Jun 29 22:35:58 ubuntu user-setup: adduser: The group `debian-tor' does not exist.
Jun 29 22:35:58 ubuntu user-setup: Adding user `userabc' to group `sudo' ...
Jun 29 22:35:58 ubuntu user-setup: Adding user userabc to group sudo
Jun 29 22:35:58 ubuntu user-setup: Done.
Jun 29 22:37:45 ubuntu ubiquity: Removing user-setup ...
Jun 29 22:37:45 ubuntu ubiquity: Purging configuration files for user-setup ...

  • The lines containing ‘Adding user userabc to group xyz’ gives the groups in which user was added which are its default groups. Manually add the user to these groups and don’t forget -a parameter.
    Login to root account.
    usermod -a -G adm,cdrom,sudo,dip,plugdev,lpadmin,sambashare userabc
  • You need to logout and again login to view the change.
  • Give command groups to view the groups. The newly added default groups should be there.