How to fix "Permission denied" when running sudo commands
Answered
8
I'm getting "Permission denied" errors when trying to run commands with sudo. The error says my user is not in the sudoers file. How can I fix this?
N
Asked by
noor_code
Gold
•
255 rep
1 Answer
19
This issue occurs when your user account is not in the sudoers group. Here are the solutions:
Solution 1: Add user to sudo group
# Login as root or another admin user
su -
# Add your user to the sudo group
usermod -aG sudo yourusername
# Log out and log back in for changes to take effect
Solution 2: Edit sudoers file directly
# Use visudo to safely edit sudoers
visudo
# Add this line at the end:
yourusername ALL=(ALL:ALL) ALL
Important: Never edit /etc/sudoers directly. Always use visudo to prevent syntax errors.
S
Silver
•
222 rep
Your Answer
You need to be logged in to answer questions.
Log In to Answer