RadarURL
유닉스/리눅스

sudo 사용자 등록 (in CentOS)

by JaeSoo posted May 27, 2014
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

sudo 사용자 등록 (in CentOS)

일반 사용자가 루트 권한을 획득하기 위해서는 su 명령을 사용해야 합니다. 사실 매번
루트 권한을 얻기 위해서 su를 수행하는 것은 불편하죠. Ubunto를 사용할 때 가장 편
리한 명령은 아마도 sudo일 것입니다. sudo는 일반사용자가 루트 권한을 임시적으로 획득하여 특정 명령을 할 수 있도록 합니다.

Ubuntu에서는 처음부터 일반 사용자가 sudo를 사용할 수 있도록 되어 있지만 CentOS >등 다른 리눅스 배포판에서는 sudo를 기본적으로 사용할 수 없도록 되어 있습니다.

[was@centos ~]$ sudo more /etc/sysctl.conf
[sudo] password for was:
was is not in the sudoers file.  This incident will be reported.
[was@centos ~]$

위 예를 보면 weblogic 사용자는 sudoers 파일에 등록되어 있지 않기 때문에 sudo를 사용할 수 없다는 메세지를 확인할 수 있습니다.

일반사용자가 sudo 명령어를 사용하기 위해서는 /etc/sudoers에 등록되어 있어야 합니다.

/etc/sudoers에 일반 사용자를 등록하는 방법은 다음과 같습니다.

  1. root로 사용자 전환 (su -)
  2. /etc/sudoers의 파일 permission 변경
    • chmod u+w /etc/sudoers
  3. /etc/sudoers에 일반 사용자 등록
  4. /etc/sudoers 퍼미션 원복
    • /etc/sudoers는 440 퍼미션이어야 함
    • chmod u-w /etc/sudoers
  5. sudo 테스트


/etc/sudoers의 초기 퍼미션은 다음과 같습니다.

1[devtainer@centos ~]$ ls -al /etc/sudoers
2-r--r----- 1 root root 3217 316 14:09 /etc/sudoers

파일 수정을 위하여 /etc/sudoers의 퍼미션을 수정해야 합니다. (root 전환 후 퍼미션 변경)

1[devtainer@centos ~]$ su -
2암호:
3[root@centos ~]# chmod u+w /etc/sudoers
4[root@centos ~]# ls -al /etc/sudoers
5-rw-r----- 1 root root 3217 316 14:09 /etc/sudoers

/etc/sudoers에 사용자 등록 방법은 다음과 같습니다. 다음과 같은 설정을 /etc/sudoers의 하단에 추가하면 설정은 완료됩니다.

case 1. 특정 사용자가 sudo를 사용할 수 있하는 설정
devtainer       ALL=(ALL)       ALL

case 2. 그룹에 포함된 모든 사용자가 sudo를 사용할 수 있하는 설정
%wheel        ALL=(ALL)       ALL

case 3. 패스워드 생략 설정
%wheel        ALL=(ALL)       NOPASSWD: ALL
devtainer        ALL=(ALL)       NOPASSWD: ALL

case 4. sudo를 사용하여 cd 마운트, 언마운트 가능하도록 설정
%users  ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
#users 그룹의 멤버는 sudo를 사용하여 cd롬 마운트와 언마운트만 허용

이제 사용자 등록이 완료된 상태 입니다. /etc/sudoers 의 퍼미션은 440이어야 합니다. 다음과 같이 퍼미션이 440이 아닐 경우에 에러가 발생됩니다. /etc/sudoers파일의 퍼미션을 440으로 변경하면 sudo명령이 정상적으로 동작하는 것을 확인할 수 있습니다.

01[devtainer@centos ~]$ sudo tail /etc/sudoers
02sudo: /etc/sudoers is mode 0640, should be 0440
03sudo: no valid sudoers sources found, quitting
04[devtainer@centos ~]$ su -
05암호:
06[root@centos ~]# chmod u-w /etc/sudoers
07[root@centos ~]# su - devtainer
08[devtainer@centos ~]$ sudo tail /etc/sudoers
09[sudo] password for devtainer:
10# %wheel ALL=(ALL) NOPASSWD: ALL
11
12## Allows members of the users group to mount and unmount the
13## cdrom as root
14# %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
15
16## Allows members of the users group to shutdown this system
17# %users localhost=/sbin/shutdown -h now
18devtainer ALL=(ALL) ALL

 

출처 : http://devtainer.blogspot.kr/2011/03/sudo-in-centos_16.html

TAG •

Articles

28 29 30 31 32 33 34 35 36 37