리눅스 계정에 특정 명령어 root 실행 권한 주기

Jmnote (토론 | 기여)님의 2012년 9월 2일 (일) 09:59 판 (→‎sudo 시도)
리눅스 사용자에게 특정 명령어를 root 권한으로 실행할 수 있게 하기
리눅스 계정에 특정 명령어 root 권한 실행할 수 있게 하기
리눅스 계정에 특정 명령어 root 실행 권한 주기
/etc/sudoers

1 방법

vi /etc/sudoers

2 실습

testuser가 sudo를 통해 httpd를 제어할 수 있게 해보자.

2.1 사전 확인

[root@jmnote ~]# ps -ef | grep httpd
root      8026     1  0 11:40 ?        00:00:00 httpd -k start
apache    8047  8026  0 11:41 ?        00:00:00 httpd -k start
apache    8048  8026  0 11:41 ?        00:00:00 httpd -k start
apache    8049  8026  0 11:41 ?        00:00:00 httpd -k start
apache    8050  8026  0 11:41 ?        00:00:00 httpd -k start
apache    8051  8026  0 11:41 ?        00:00:00 httpd -k start
apache    8052  8026  0 11:41 ?        00:00:00 httpd -k start
apache    8053  8026  0 11:41 ?        00:00:00 httpd -k start
apache    8054  8026  0 11:41 ?        00:00:00 httpd -k start
apache    8525  8026  0 13:05 ?        00:00:00 httpd -k start
apache    8557  8026  0 13:11 ?        00:00:00 httpd -k start
root      8565  7814  0 13:12 pts/0    00:00:00 grep httpd
→ 현재 httpd는 root가 시작한 상태.

2.2 계정 생성

[root@jmnote ~]# useradd testuser
[root@jmnote ~]# echo 'P@ssw0rd' | passwd --stdin testuser
Changing password for user testuser.
passwd: all authentication tokens updated successfully.
→ 실습을 위해 testuser 계정 생성하고 패스워드를 P@ssw0rd로 지정.

2.3 sudo 시도

[root@jmnote ~]# su - testuser
[testuser@jmnote ~]$ sudo /usr/sbin/httpd -k stop
[sudo] password for testuser:
→ sudo로 root 권한 httpd 종료 시도. testuser의 패스워드를 물어본다.
testuser is not in the sudoers file.  This incident will be reported.
→ 패스워드가 맞더라도 위와 같이 sudoers에 설정되지 않아 수행 불가

2.4 권한 부여

[testuser@jmnote ~]$ logout
[root@jmnote ~]# cp /etc/sudoers /etc/sudoers.20120613
[root@jmnote ~]# echo 'testuser ALL=/usr/sbin/httpd' >> /etc/sudoers
[root@jmnote ~]# tail -5 /etc/sudoers

## Allows members of the users group to shutdown this system
# %users  localhost=/sbin/shutdown -h now

testuser ALL=/usr/sbin/httpd
→ sudoers 파일을 백업해두고, 맨아래에 한줄을 삽입하여 testuser 권한을 추가하고 확인

2.5 sudo 시도

아파치 종료
[root@jmnote ~]# su - testuser
[testuser@jmnote ~]$ sudo /usr/sbin/httpd -k stop
[sudo] password for testuser:
→ testuser의 패스워드를 입력하여 httpd가 종료된다.
[testuser@jmnote ~]$ ps -ef | grep httpd
testuser  8635  8584  0 13:14 pts/0    00:00:00 grep httpd
→ httpd 종료된 것 확인.
아파치 시작
[root@jmnote ~]$ ps -ef | grep httpd
root     11901     1  6 09:57 ?        00:00:00 /usr/sbin/httpd -k start
apache   11902 11901  0 09:57 ?        00:00:00 /usr/sbin/httpd -k start
apache   11903 11901  0 09:57 ?        00:00:00 /usr/sbin/httpd -k start
apache   11904 11901  0 09:57 ?        00:00:00 /usr/sbin/httpd -k start
... (생략)
→ 아파치가 root 계정으로 실행된다. (sudoer는 권한을 위임한다.)

2.6 원상복구

실습 전 상황으로 되돌린다(root 권한으로 수행). sudoer 파일을 복구하고 백업본은 삭제. testuser 계정 삭제. httpd 시작.

\cp /etc/sudoers.20120613 /etc/sudoers
rm -f /etc/sudoers.20120613 
userdel -r testuser
httpd -k start

3 같이 보기

4 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}