To remove a user from a specific group like sudo, you use the gpasswd command or the deluser command.
Since you are currently logged in as joker in your terminal history, first make sure to type exit to return to the labex user (who still has administrative power).
Then, run this command:
sudo gpasswd -d joker sudo
Breakdown of the command:
sudo: You need administrator rights to change group memberships.gpasswd: This is a tool used to administer/etc/group.-d: This flag stands for delete user from the group.joker: The username.sudo: The group name you want to remove them from.
Alternative Method:
You can also use the deluser command, which is very readable:
sudo deluser joker sudo
How to verify:
Run the groups command again for joker:
groups joker
You should now see that sudo is missing from the list. If joker tries to run sudo cat /etc/shadow now, they will receive a message saying: "joker is not in the sudoers file. This incident will be reported."
Note: If the user joker is currently logged in, the change won't take effect for their active session. They would need to log out and log back in for the system to realize they no longer have sudo privileges.