Jenkins sudo: no tty present and no askpass program specified with NOPASSWD
I've tested the solution described by @Jayan in the comments of the question. You must include the new line at the end of the file:
Solution: https://stackoverflow.com/a/24648413/54506
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
jenkins ALL=(ALL) NOPASSWD: ALL
sudoers NOPASSWD: sudo: no tty present and no askpass program specified
sudo
permissions are about the user/group you are changing from not the user you are changing to.
So are those permission lines are letting the testuser
user and the testgroup
group run any command (as anyone) without a password.
You need to give permission to the user running the script to run commands as the testuser
user for what you want.
Assuming that's what you meant to allow that is.
sudo: no tty present and no askpass program specified in github actions
So I went over this with my team, and we figured it out. We updated the sudoers file on the runner machine.
/etc/sudoers
Added in this line:
admin ALL=(ALL) NOPASSWD: ALL
And everything just worked.
sudo: no tty present and no askpass program specified When useing shell_exec
Although my setup is a little different (I'm not trying to achieve it without a password), I use this in the sudoers file:
apache ALL=(ALL) ALL
Defaults:apache !requiretty
I then run things as:
echo '{password}' | sudo -S {command}
shell script giving sudo: no tty present and no askpass program specified when trying to execute sudo command
Try to replace this:
su - devops -c "sh /path/to/myscript.sh"
with this:
sudo -u devops -H sh -c "sh /path/to/myscript.sh"
The -c
option of su
doesn't support interactive mode:
-c, --command COMMAND
Specify a command that will be invoked by
the shell using its -c.The executed command will have no controlling terminal. This option
cannot be used to execute interractive programs which need a
controlling TTY.
(man su
)
By the way, I wouldn't use sudo
within a script everywhere. The script might simply require root
permissions. Within the script you might drop privileges where necessary by means of the above-mentioned sudo
command.
Related Topics
Why Do We Need to Call Poll_Wait in Poll
Bash: No Such File or Directory
What's the Max File Mapping Size in 64Bits MAChine
Shell Command to Update Pom File from a Variable
What's the Difference Between 'Push' and 'Pushq' in At&T Assembly
What Does It Take to Be Durable on Linux
Best Approach to Detecting a Move or Rename to a File in Linux
Interrupting Syscalls in Threads on Linux
Why Non-Pic Code Can't Be Totally Aslr Using Run-Time Fixups
Jni Issue on Linux: Cannot Open Shared Object File
How to Join Multiple PDF Pages to a Single Page
Error Marking Master: Timed Out Waiting for the Condition [Kubernetes]
Haskell Ghc Compiling/Linking Error, Not Creating Executable. (Linux)
Perl: What Does Checkstack.Pl in Linux Source Do