[Linux]sudo 명령어 수행 시 sudo: sorry, you must have a tty to run do Error가 발생할 때 해결 방안
1. 현상
특정 유저의 crontab이나 zabbix 계정으로 실행되는 zabbix agent 에서 root 권한의 명령어를 수행하고 싶다면 sudo를 사용하면 된다.
문제는 sudo 관련하여 /etc/sudoers에 해당 계정의 권한을 설정했음에도, 아래와 같은 로그를 남기며 명령어 수행을 실패하는 경우가 있다.
sudo: sorry, you must have a tty to run sudo
2. 원인
해당 원인을 분석한 결과 /etc/sudoers 파일 내 Defaults requiretty 값이 설정되어 위와 같은 에러가 발생했다. Defaults requiretty 이 설정되면 cron 이나 agent 내부에서 sudo 명령어 실행이 불가능하며, 실제 tty(teletyperwriter, Linux 콘솔 or 터미널) 를 통해 접속된 상태에서만 sudo 명령어 실행이 가능하다.
[man page 내 requiretty 관련 guide]
requiretty
If set, sudo will only run when the user is logged in to a real tty. When this flag is set, sudo can only be run from a login session and not via other means such as cron(8) or cgi-bin scripts. This flag is off by default.
3. 해결방안
visudo 또는 /etc/sudoers 파일을 vi 편집기로 Open 한 후
Defaults requiretty 구문을 주석(#) 처리하면 된다.
'Linux' 카테고리의 다른 글
[Linux] systemctl status 실행 시 state : degraded 경우 해결법 (0) | 2018.07.19 |
---|---|
[Linux] HPE 스마트 스토리지 관리자(HPE SSA) CLI 를 활용한 서버 Disk 상태 확인 (0) | 2018.07.19 |
[Linux] CentOS7에서 2TB 이상 사이즈의 디스크 GTP 파티션 생성 및 포맷 방법 (0) | 2018.07.07 |
[Linux] CentOS 7, rhel7 hostname 호스트네임 변경하기 (0) | 2018.07.02 |
[Linux] CentOS SFTP 서버 설정하기 - chroot로 디렉토리 제한 및 SSH와 포트 분리까지 (0) | 2018.06.26 |