🔓 Sudoers NOPASSWD: Run `sudo`

Sometimes you need your scripts or commands to run without having to type your password every time you use sudo.
That’s where NOPASSWD, but use it carefully! 🚨


💡 Quick Command: Enable NOPASSWD for Current User

echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/$USER

This adds a NOPASSWD rule for the current user without editing the main sudoers file.


📄 Manual Method: Edit the sudoers File

1️⃣ Open sudoers Safely

sudo visudo

Always use visudo — it checks for syntax errors before saving.
A bad sudoers file can lock you out of administrative privileges.


2️⃣ Add the NOPASSWD Rule

For a single user:

myuser ALL=(ALL:ALL) NOPASSWD: ALL

For a group:

%sudo ALL=(ALL:ALL) NOPASSWD: ALL

If you don’t want to allow all commands without a password, you can limit it:

username ALL=(ALL) NOPASSWD: /usr/bin/apt, /usr/bin/systemctl

This way, the user can run only apt and systemctl without entering a password.


✅ Testing the Setup

After saving (Ctrl+X, then Y in visudo), check your permissions:

sudo -l

You should see your NOPASSWD rules listed.


⚠️ Security Notes

  • Avoid NOPASSWD: ALL unless absolutely necessary.
  • Always limit commands when possible.
  • Only grant NOPASSWD to trusted users.

💻 Done!
Now your user can run sudo commands without being prompted for a password — perfect for automation, cron jobs, and scripts.

🚀 Explore more guides on our blog 👉 blog.1it.pro
📧 Contact us: admin@1it.pro for expert IT guidance.
🌐 Explore more: Visit 1it.pro for top-tier IT solutions.

UA EN RU

Зв'язатися з нами

Telegram Email