π ~1 min read
Table of contents
Symptom & Impact
Cron or CI scripts fail with ‘sudo: no tty present and no askpass program specified’ on Ubuntu 22.04.
Environment & Reproduction
Ubuntu 22.04 scheduled jobs running privileged commands without interactive terminal and without NOPASSWD sudoers rules.
Root Cause Analysis
sudo requires authentication context; non-interactive shells cannot prompt unless explicit policy or askpass helper is configured.
Quick Triage
Validate execution context with env output, inspect sudo -l for job user, and confirm command path exactness.
Step-by-Step Diagnosis
Review /etc/sudoers and /etc/sudoers.d entries using visudo -c, then inspect cron logs for failing command patterns.

Solution – Primary Fix
Grant least-privilege NOPASSWD for exact commands in sudoers.d, use absolute paths, and remove interactive assumptions from scripts.
Still having issues? Our IT Solutions & Services team can diagnose and resolve this for you. Get in touch for a free consultation.

Solution – Alternative Approaches
Use systemd service units with proper User/Group and capabilities, or execute tasks as root-owned controlled timers.
Verification & Acceptance Criteria
Scheduled job completes successfully without prompt errors and only approved privileged commands are permitted.
Rollback Plan
Disable new sudoers drop-in and restore previous policy if command scope was overly broad or incorrect.
Prevention & Hardening
Use version-controlled sudo policy, enforce visudo validation in pipelines, and audit privileged automation regularly.
Related Errors & Cross-Refs
Related Ubuntu 22.04 access issues include expired credentials caches and incorrect PAM/SSH session assumptions.
Related tutorial: View the step-by-step tutorial for Ubuntu 22.04 LTS.
View all Ubuntu 22.04 LTS tutorials on the Tutorials Hub β
Browse all common problems & solutions on the Tutorials Hub.
References & Further Reading
man sudoers, Ubuntu sudo hardening docs, cron/systemd timer guides, and least-privilege best practices.
Need Expert Help?
If you cannot resolve this yourself, our team offers hands-on Server Management, Managed IT Services, and flexible Support Plans. Contact us today β we respond within one business day.