Accidentally Removed Your Sole Ubuntu User From All Groups? Here’s How to Fix It
Linux is unlike other major operating systems in that it gives you freedom. Freedom to use it in whatever way you like, freedom to study and change it, freedom to distribute it however you choose, and freedom to lock yourself out of vital groups.
Here’s what you need to do in case you’ve removed your only user from all groups on Ubuntu.

How Do Groups Work on Linux?
On Linux, groups contain privileged users who are variously able to read, write, or execute files without additional authorization. When you create your primary user account, you are automatically added to your primary groups. On a standard Ubuntu install, these are usuallyadm,cdrom,sudo,dipb,plugdev, andsambashare.
You can add yourself to other groups using theusermodcommand:

The-Gswitch means that you will be adding the user to a supplemental group, and the-astands for append, meaning that the group will be added to your list of groups.
Executing the above command without the-ameans that the new group will replace all of your old groups.

Most importantly the command will remove you from the sudo group, meaning that your powers will be severely limited. Without being part of thesudogroup, you can’t add yourself to the sudo group, you can’t install software, or even update the system.
What to Do if You Accidentally Erase Your User’s Groups
It’s a small thing, but missing that-acan totally ruin your day. Fortunately, the solution is simple, but you can’t fix the mistake from within your Ubuntu install as you no longer have admin privileges. You need a root shell.
First, you will need to access the GRUB menu. Do this by rebooting your PC and repeatedly hittingEscapeuntil the menu appears.

ChooseAdvanced Ubuntu Options, thenRecovery Mode.
When the menu gives you an option for a root shell, choose this. The shell will appear at the bottom of the screen.

Commands executed in the root shell are carried out as root, and on a standard Ubuntu system, do not need a password.
Enter the following command to add yourself to the sudo group:
Now reboot. When you log back into your system, you will again be part of the sudo group and able to carry out actions that require root privileges.
Rejoin Your Previous User Groups on Linux
Linux logs everything. This can be a problem when your logs grow to a ridiculous size, but if you need to know which groups your user was previously a part of, it can be invaluable.
…will output every time a user was added to a group. Take note of the group names, then, re-add them with:
Note that there is no space between the group names and the commas.
Log out and back in again, and your groups will be fully restored.
Groups Make Linux Administration Easy
So long as you don’t accidentally remove your own privileges, groups are an incredibly powerful tool on Ubuntu and other Linux distros. With them, you’re able to manage large numbers of users and ensure that everyone has appropriate access and permissions for what they need and aren’t able to damage your system by accident.
By using groups, you’re able to choose which people can be trusted enough to read, write, and execute files. It’s easy to move users between groups, and if you want someone to have complete freedom to use a particular file, you can even give them ownership.
Need to manage multiple users on your Linux system? Here’s how to do that with groupadd, usermod, and other commands.
Not Linux, not Windows. Something better.
Make sure you don’t miss these movies and shows before Netflix removes them.
You can block out the constant surveillance and restore your privacy with a few quick changes.
You don’t need to fork out for expensive hardware to run an AI on your PC.
I found my TV was always listening—so I shut it down.