Skip to content

Q&A · Answered

How to fix "Permission denied" when running sudo commands

asked 9 months, 1 week ago 752 views 1 answer
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?

1 Answer

One accepted
19

Accepted answer

Not confirmed since it was written, 9 months, 1 week ago

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.

Your answer

Say what you tried, not only what worked — the next person needs the reasoning. Code goes in a fenced block.

Shown beside your answer and never checked, so it cannot be a name someone already has here.

No account needed to answer. Sign in instead and it carries your name and earns reputation.