Jenkins sudo: no tty present and no askpass program specified

DG
4 min readFeb 6, 2020

--

현재 학교 내 서버에 올라간 노드 서버 컨테이너의 배포 자동화를 위해서 Jenkins를 사용중인데, Jenkins에서 자동으로 실행시켜줄 script문들중 권한 문제로 인해서 permission denied 에러를 받고 있는 상황이었다. script내에 sudo 를 입력해야 하는데, sudo 명령어를 Jenkis user가 실행하면 다음과 같은 에러가 발생한다.

sudo: no tty present and no askpass program specified.

Jenkins user에게 sudo 명령어 실행 권한을 주기 위해서 자료를 검색해보고 아주 간단한 솔루션을 찾았다.

/etc/sudoers 파일을 조금 수정해주면 된다.

#
# 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

이게 원본 모습. 가장 마지막 줄에 한줄만 추가해준다.

#
# 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

--

--

DG
DG

Written by DG

한국의 iOS 개발자이다. 강아지와 운동을 좋아함. github: https://github.com/donggyushin

No responses yet