출처 : https://askubuntu.com/questions/878170/allow-systemd-service-to-be-started-or-stopped-by-non-sudo-user



두 가지 정도의 방법이 있는 것 같다. 


우선 사용자를 추가한다.

useradd -m webuser

passwd webuser


ROOT 권한 주기

사용자 계정으로 sudo 실행을 하면 비밀번호를 묻지않고 동작 시킨다.
sudo 없이 실행하면 ROOT계정의 비밀번호를 물어본다.

visudo -f /etc/sudoers

# 다음을 추가

## Allow root to run any commands anywhere

root    ALL=(ALL)    ALL

webuser    ALL=(ALL)    ALL


특정명령어에만 ROOT 권한 주기

사용자 계정으로 sudo 명령을 처리할 때 특정 명령만 root 권한으로 실행할 수 있도록 허가해주는 방법

visudo -f /etc/sudoers.d/webuser

# webuser는 그냥 파일명이므로 필요에 따라 변경한다(거의 파일을 새로 만들어 관리한다)

Cmnd_Alias WEB_CMDS = /bin/systemctl start WebServer, /bin/systemctl stop WebServer

%webuser ALL=(ALL) NOPASSWD: WEB_CMDS


# 파일 생성후에는 적당한 접근권한을 준다

chmod 0440 /etc/sudoers.d/webuser










Posted by motolies
,