- 참고로 해당 내용은 CentOS 7 을 기준으로 작성하였습니다.

특정 사용자(wheel 그룹)만 su 명령어 사용

아래 빨간색으로 강조된 부분 "auth required pam_wheel.so use_uid" 의 주석을 제거 하시면 됩니다.

[root@localhost ~]# vim /etc/pam.d/su

#%PAM-1.0
auth        sufficient  pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth       sufficient  pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
auth        required    pam_wheel.so use_uid
auth        substack    system-auth
auth        include     postlogin
account     sufficient  pam_succeed_if.so uid = 0 use_uid quiet
account     include     system-auth
password    include     system-auth
session     include     system-auth
session     include     postlogin
session     optional    pam_xauth.so

wheel 그룹에 사용자 추가

위에서 su 명령어 사용을 wheel 그룹에 포함된 사용자로 제한하였습니다.
그러면 이제 su 명령어를 사용할 계정을 wheel 그룹에 추가하겠습니다.

[root@localhost ~]# vim /etc/group

root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mem:x:8:
kmem:x:9:
wheel:x:10:root,hong,kim

...

위와 같이 "wheel:x:10:사용자계정" 이런식으로 계정을 추가해주세요(그룹에 추가하는 명령어도 있지만 그냥 직접 추가해도 됩니다).


su 파일의 권한 수정

일반 사용자는 사용하지 못하게 하고 wheel 그룹에 속한 사용자만 su 명령어를 사용할 수 있도록 권한을 수정합니다.

[root@localhost ~]# which su
/bin/su
[root@localhost ~]# ll /bin/su
-rwsr-xr-x. 1 root root 32096 Apr 13 05:43 /bin/su

먼저 su 위치를 which 명령어를 이용하여 확인하고 ll 명령어로 조회 합니다. 그러면 위처럼 "-rwsr-xr-x. 1 root root" 이런 권한을 가지고 있을 겁니다.


[root@localhost ~]# chgrp wheel /bin/su
[root@localhost ~]# ll /bin/su
-rwxr-xr-x. 1 root wheel 32096 Apr 13 05:43 /bin/su

su 사용 그룹 권한을 wheel로 변경 합니다. wheel 그룹으로 변경하면 위와 같이 su 파일의 Permission 이 rws 에서 rwx 로 변경 된 것을 알수 있습니다.


[root@localhost ~]# chmod 4750 /bin/su
[root@localhost ~]# ll /bin/su
-rwsr-x---. 1 root wheel 32096 Apr 13 05:43 /bin/su

Permission 정보를 4750 으로 변경하면 끝.