7

I have setup my container with the following in my /etc/sudoers file username ALL=(ALL) NOPASSWD: ALL

This works in previous versions, (22.04, 20.04) but in Ubuntu 24.04 I'm getting this error:

sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper sudo: a password is required

David DE
  • 2,316
Diarmuid
  • 71
  • 1
  • 3

4 Answers4

6

The order is important

From the sudoers manual:

When multiple entries match for a user, they are applied in order. Where there are multiple matches, the last match is used (which is not necessarily the most specific match).

If you want that username does not enter the password each time he does a sudo and he is already a member of sudo, the entry in sudoers must be after the %sudo entry.

Correct

# Allow members of group sudo to execute any command
%sudo     ALL=(ALL:ALL) ALL
username  ALL=(ALL) NOPASSWD: ALL

Incorrect

# User privilege specification 
root      ALL=(ALL:ALL) ALL
username  ALL=(ALL) NOPASSWD: ALL

Members of the admin group may gain root privileges

%admin ALL=(ALL) ALL

Allow members of group sudo to execute any command

%sudo ALL=(ALL:ALL) ALL

estibordo
  • 1,419
3

In my case, /etc/sudoers.d contains a file that overrides the permission. 10-installer. Removing this file fixed the issue, this file contains a single line override as following:

%sudo ALL=(ALL:ALL) ALL

So the contents in the /etc/sudoers.d overrides the content in the sudoer.

2017561-1
  • 520
  • 1
  • 7
  • 19
0

In this instance, updating the %sudo setting in the /etc/sudoers file to NOPASSWD worked.

sed -i -e 's/^%sudo\tALL=(ALL:ALL) ALL/%sudo\tALL=(ALL) NOPASSWD: ALL/g' /etc/sudoers

Before

sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper sudo: a password is required

After

sudo apt install vim -y WARNING: apt does not have a stable CLI interface. Use with caution in scripts. Reading package lists...

Diarmuid
  • 71
  • 1
  • 3
0

on noble numbat this way worked :

sudo visudo -f /etc/sudoers.d/nopasswd

(user)  ALL=(ALL) NOPASSWD: ALL

or

(user) ALL=(ALL) NOPASSWD: /usr/bin/journalctl -f


afaik on previous version or on any distro linux specify user on sudo.conf under tag "#user privilege spec" under root worked, maybe bad or just not neat practice.

Junbr0
  • 1