When adding a user to a group in Linux, a "permission denied" error indicates insufficient privileges. Resolve this quickly with admin access.
Common Solutions
- Use Sudo: Prefix commands with sudo to gain root privileges.
Run: sudo usermod -aG groupname username (replace groupname and username).
Example: sudo usermod -aG sudo johndoe adds user johndoe to sudo group.
- Switch to Root User: Execute su -, enter root password, then run commands without sudo.
For instance: usermod -aG groupname username.
Verification and Troubleshooting
- Confirm group addition: Run groups username or id username to check membership.
- If sudo is denied, ensure your user is in the sudoers file. Edit it safely via sudo visudo and add a line like: username ALL=(ALL:ALL) ALL.
- Always log out and back in after changes: Run newgrp groupname or reboot.
These fixes resolve most permissions issues efficiently. Always handle admin tasks carefully.