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

경고: 로그인하지 않았습니다. 편집을 하면 IP 주소가 공개되게 됩니다. 로그인하거나 계정을 생성하면 편집자가 사용자 이름으로 기록되고, 다른 장점도 있습니다.

편집을 취소할 수 있습니다. 이 편집을 되돌리려면 아래의 바뀐 내용을 확인한 후 게시해주세요.

최신판 당신의 편집
3번째 줄: 3번째 줄:
;리눅스 계정에 특정 명령어 root 실행 권한 주기
;리눅스 계정에 특정 명령어 root 실행 권한 주기
;/etc/sudoers
;/etc/sudoers
;user1 is not in the sudoers file.  This incident will be reported.


==방법==
==방법==
11번째 줄: 10번째 줄:


==실습==
==실습==
*testuser 계정으로 아파치와 MySQL을 제어할 수 있게 해보자.
testuser가 sudo를 통해 httpd를 제어할 수 있게 해보자.
*적용 후에도 시작/종료 등의 권한만 있을 뿐, 프로세스 실제 소유자는 root가 된다.<ref>testuser가 아님. 즉 root가 실행한 것과 같음.</ref>


===사전 확인===
===사전 확인===
<source lang='console'>
<source lang='dos'>
[root@zetawiki ~]# ps -ef | grep httpd
[root@jmnote ~]# ps -ef | grep httpd
root      8026    1  0 11:40 ?        00:00:00 httpd -k start
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    8047  8026  0 11:41 ?        00:00:00 httpd -k start
33번째 줄: 31번째 줄:


===계정 생성===
===계정 생성===
<source lang='console'>
<source lang='dos'>
[root@zetawiki ~]# useradd testuser
[root@jmnote ~]# useradd testuser
[root@zetawiki ~]# echo 'P@ssw0rd' | passwd --stdin testuser
[root@jmnote ~]# echo 'P@ssw0rd' | passwd --stdin testuser
Changing password for user testuser.
Changing password for user testuser.
passwd: all authentication tokens updated successfully.
passwd: all authentication tokens updated successfully.
42번째 줄: 40번째 줄:


===sudo 시도===
===sudo 시도===
<source lang='console'>
<source lang='dos'>
[root@zetawiki ~]# su - testuser
[root@jmnote ~]# su - testuser
[testuser@jmnote ~]$ sudo /usr/sbin/httpd -k stop
[testuser@jmnote ~]$ sudo /usr/sbin/httpd -k stop
[sudo] password for testuser:  
[sudo] password for testuser:  
</source>
</source>
:→ sudo로 root 권한 [[httpd]] 종료 시도. testuser의 패스워드를 물어본다.
:→ sudo로 root 권한 [[httpd]] 종료 시도. testuser의 패스워드를 물어본다.
<source lang='console'>
<source lang='dos'>
testuser is not in the sudoers file.  This incident will be reported.
testuser is not in the sudoers file.  This incident will be reported.
</source>
</source>
54번째 줄: 52번째 줄:


===권한 부여===
===권한 부여===
<source lang='console'>
<source lang='dos'>
[testuser@jmnote ~]$ logout
[testuser@jmnote ~]$ logout
[root@zetawiki ~]# cp /etc/sudoers /etc/sudoers.20120613
[root@jmnote ~]# cp /etc/sudoers /etc/sudoers.20120613
[root@zetawiki ~]# echo 'testuser ALL=NOPASSWD:/usr/sbin/httpd, /etc/rc.d/init.d/mysqld' >> /etc/sudoers
[root@jmnote ~]# echo 'testuser ALL=NOPASSWD:/usr/sbin/httpd, /etc/rc.d/init.d/mysqld' >> /etc/sudoers
[root@zetawiki ~]# tail -5 /etc/sudoers
[root@jmnote ~]# tail -5 /etc/sudoers


## Allows members of the users group to shutdown this system
## Allows members of the users group to shutdown this system
66번째 줄: 64번째 줄:
</source>
</source>
:→ sudoers 파일을 백업해두고, 맨아래에 한줄을 삽입하여 testuser 권한을 추가하고 확인
:→ sudoers 파일을 백업해두고, 맨아래에 한줄을 삽입하여 testuser 권한을 추가하고 확인
:→ 일반적인 설정에서는 sudo를 할 때마다 자신(testuser)의 패스워드를 입력받게 되어 있으나, 위 예시처럼 <code>NOPASSWD:</code>를 넣어주면 패스워드를 물어보지 않는다.


===sudo 시도===
===sudo 시도===
;아파치 종료
;아파치 종료
<source lang='console'>
<source lang='dos'>
[root@zetawiki ~]# su - testuser
[root@jmnote ~]# su - testuser
[testuser@jmnote ~]$ sudo /usr/sbin/httpd -k stop
[testuser@jmnote ~]$ sudo /usr/sbin/httpd -k stop
[sudo] password for testuser:
</source>
:→ testuser의 패스워드를 입력하여 httpd가 종료된다.
<source lang='dos'>
[testuser@jmnote ~]$ ps -ef | grep httpd
[testuser@jmnote ~]$ ps -ef | grep httpd
testuser  8635  8584  0 13:14 pts/0    00:00:00 grep httpd
testuser  8635  8584  0 13:14 pts/0    00:00:00 grep httpd
79번째 줄: 80번째 줄:


;아파치 시작
;아파치 시작
<source lang='console'>
<source lang='dos'>
[testuser@jmnote ~]$ sudo /usr/sbin/httpd -k start
[testuser@jmnote ~]$ sudo /usr/sbin/httpd -k start
[testuser@jmnote ~]$ ps -ef | grep httpd
[testuser@jmnote ~]$ ps -ef | grep httpd
91번째 줄: 92번째 줄:


;MySQL 재시작
;MySQL 재시작
<source lang='console'>
<source lang='dos'>
[testuser@jmnote ~]$ sudo /etc/rc.d/init.d/mysqld restart
[testuser@jmnote ~]$ sudo /etc/rc.d/init.d/mysqld restart
Stopping MySQL:                                            [  OK  ]
Stopping MySQL:                                            [  OK  ]
98번째 줄: 99번째 줄:


===원상복구===
===원상복구===
실습 전 상황으로 되돌린다(root 권한으로 수행). sudoer 파일을 복구하고 백업본은 삭제. testuser 계정 삭제. 아파치, MySQL 재시작.
실습 전 상황으로 되돌린다(root 권한으로 수행). sudoer 파일을 복구하고 백업본은 삭제. testuser 계정 삭제. httpd 재시작.
;명령어
<source lang='bash'>
<source lang='bash'>
\cp /etc/sudoers.20120613 /etc/sudoers
\cp /etc/sudoers.20120613 /etc/sudoers
rm -f /etc/sudoers.20120613  
rm -f /etc/sudoers.20120613  
userdel -r testuser
userdel -r testuser
service httpd restart
httpd -k restart
service mysqld restart
/etc/rc.d/init.d/mysqld restart
</source>
;실행예시
<source lang='console'>
[root@zetawiki ~]# \cp /etc/sudoers.20120613 /etc/sudoers
[root@zetawiki ~]# rm -f /etc/sudoers.20120613
[root@zetawiki ~]# userdel -r testuser
[root@zetawiki ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@zetawiki ~]# service mysqld restart
Stopping MySQL:                                            [  OK  ]
Starting MySQL:                                            [  OK  ]
</source>
</source>


==같이 보기==
==같이 보기==
* [[/etc/sudoers]]
*[[/etc/sudoers]]
* [[sudo 패스워드 없이 사용]]
* [[sudo]]
* [[su]]
* [[Bash 스크립트 root로 실행하게 하기]]
 
==주석==
<references/>


==참고==
==참고 자료==
*http://blog.naver.com/opalcosmos/90033450548
*http://blog.naver.com/opalcosmos/90033450548


[[분류: 리눅스 계정]]
[[분류: 리눅스 계정]]
[[분류: /etc]]
[[분류: /etc]]

제타위키에서의 모든 기여는 크리에이티브 커먼즈 저작자표시-동일조건변경허락 3.0 라이선스로 배포된다는 점을 유의해 주세요(자세한 내용에 대해서는 제타위키:저작권 문서를 읽어주세요). 만약 여기에 동의하지 않는다면 문서를 저장하지 말아 주세요.
또한, 직접 작성했거나 퍼블릭 도메인과 같은 자유 문서에서 가져왔다는 것을 보증해야 합니다. 저작권이 있는 내용을 허가 없이 저장하지 마세요!

취소 편집 도움말 (새 창에서 열림)