본문 바로가기

리눅스-기초명령어/파일 및 유저 권한

ACL (Access Control List)

*활용도는 높으나 실제로 실무에서는 제한되어 사용됨

접근제어 목록의 약자이며 user,group,orher 영역의 권한을 부여할수 있게 만들어준다. 일반적으로 어떠한 파일에 특정 사용자나 그룹에 권한을 부여하려면 소유권한을 넘기고 다시 허가권을 부여하는 절차가 필요한데 이 문제점을 해결할 수 있는 것이 ACL이다. 

 

1. getfacl

파일이나 디렉토리에 설정된 접근권한 리스트를 확인하는 명령

 

사용법

getfacl [옵션] 파일명

 

[root@Linux ~]# getfacl /etc/passwd
getfacl: Removing leading '/' from absolute path names
# file: etc/passwd
d
# owner: root
# group: root
user::rw-
group::r--
other::r--

passwd파일의 권한을 알아 보았다.

 

2. setfacl

파일이나 디렉토리에 접근권한 리스트를 설정하는 명령으로 root 사용자만 이용할 수 있다. 

 

사용법 

setfacl [옵션] [user:유저아이디:rwx(권한)] [파일명] 으로 실행

 

옵션

옵션 설명
-m ACL을 설정한다.
-x ACL을 삭제한다.
-R 디렉토리인 경우 내용까지 권한을 변경한다.
-b 모든 ACL을 삭제한다.






setfacl [옵션] [user:유저아이디:rwx(권한)] [파일명] 으로 실행하며 

[root@Linux ~]# getfacl /etc/ssh/sshd_config
getfacl: Removing leading '/' from absolute path names
# file: etc/ssh/sshd_config
# owner: root
# group: root
user::rw-
group::---
other::---



ACL을 이용한 권한 부여

setfacl [-m] [user:유저아이디:rwx(권한)] [파일명]

[root@Linux ~]# setfacl -m user:1000:rwx happy.txt
[root@Linux ~]# getfacl happy.txt
# file: happy.txt
# owner: root
# group: root
user::rw-
user:admin:rwx
group::r--
mask::rwx   최고 권한
other::r--



[root@Linux ~]# ls -l happy.txt
-rw-rwxr--+ 1 root root 1 Apr 27 16:41 happy.txt

+표시가 있으면 확장 ACL가 있다는 것을 의미

그룹 권한자리에 rwx는 마스크의 권한을 의미

최고 권한이 어드민보다 적을 경우

[root@Linux ~]# setfacl -m mask::rw happy.txt
[root@Linux ~]# getfacl happy.txt
# file: happy.txt
# owner: root
# group: root
user::rw-
user:admin:rwx #effective:rw- 실제 적용되는 권한
group::r--
mask::rw-
other::r--




2.1. 자주 사용 하는 옵션

 

-m: ACL설정을 할때 사용한다 modify

[root@Linux system]# setfacl -m user:1000:rwx test.txt
[root@Linux system]# getfacl test.txt
# file: test.txt
# owner: root
# group: root
user::rw-
user:admin:rwx
group::r-x
mask::rwx
other::r--

 

-x : 삭제

[root@Linux system]# setfacl -x user:1000 test.txt
[root@Linux system]# getfacl test.txt
# file: test.txt
# owner: root
# group: root
user::rw-
group::r-x
mask::r-x
other::r--

아까 설정했던 admin 권한이 사라졌다.

 

-b : 초기값 (모든 권한 초기상태)

[root@Linux system]# getfacl test.txt
# file: test.txt
# owner: root
# group: root
user::rw-
user:admin:rwx #effective:rw-
group::r-x #effective:r--
mask::rw-
other::r--

[root@Linux system]# setfacl -b test.txt
[root@Linux system]# getfacl test.txt
# file: test.txt
# owner: root
# group: root
user::rw-
group::r--
other::r--

초기 설정대로 돌아왔다.

 

-k : default값 삭제

[root@Linux system]# getfacl ACLT
# file: ACLT
# owner: root
# group: root
user::rwx
user:admin:rwx
group::r-x
mask::rwx
other::r-x
default:user::rwx
default:user:admin:rwx
default:group::r-x
default:mask::rwx
default:other::r-x
[root@Linux system]# setfacl -k ACLT
[root@Linux system]# getfacl ACLT
# file: ACLT
# owner: root
# group: root
user::rwx
user:admin:rwx
group::r-x
mask::rwx
other::r-x

 

3 권한 적용 순서 

파일에 액세스할 수 있는지를 확인할 때 파일 권한 및 ACL이 다음과 같이 적용된다.

 

  • 프로세스가 파일을 소유하고 있는 사용자로 실행되는 경우 파일의 사용자 권한이  적용된다.

 

  • 프로세스가 사용자 ACL 항목에 나열된 사용자로 실행 중인 경우에는 명명된 사용자 ACL권한이 적용된다

 

  • 프로세스 파일의 그룹 소유자와 일치하는 그룹 또는 명시적으로 명명된 그룹 ACL 항목이 있는 그룹으로 실행되는 경우 일치하는 ACL권한이 적용된다. (마스크에서 허용된 경우)

 

  • 그렇지 않은 경우에는 파일의 Other ACL사용 권한이 적용된다.




4 파일 퍼미션과 ACL 의 차이점

 

  파일 퍼미션 ACL
명령어 chmod, umask getfacl, setfacl
권한 지정 대상 단일 대상 특정 사용자, 그룹으로 디렉터리나 파일의 권한을 줄 수 있다. 
기본값 권한 계정 로그인시 적용 폴더 별로 적용








배쉬 오류 발생시

 

ps -ef | head 명령어로 현재 작업중인 프로스세스 확인

 

[root@Linux /]# ps -ef | head
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 10:35 ?        00:00:01 /usr/lib/systemd/systemd rhgb --switched-root --system --deserialize 31
root           2       0  0 10:35 ?        00:00:00 [kthreadd]
root           3       2  0 10:35 ?        00:00:00 [rcu_gp]
root           4       2  0 10:35 ?        00:00:00 [rcu_par_gp]
root           5       2  0 10:35 ?        00:00:00 [netns]
root           7       2  0 10:35 ?        00:00:00 [kworker/0:0H-events_highpri]
root           9       2  0 10:35 ?        00:00:00 [kworker/0:1H-events_highpri]
root          10       2  0 10:35 ?        00:00:00 [mm_percpu_wq]
root          12       2  0 10:35 ?        00:00:00 [rcu_tasks_kthre]

가장 마지막에 적힌 창이 현재 작업중인 bash

오류가 발생한 프로세스를 kill -9 [PID number]로 제거

 

'리눅스-기초명령어 > 파일 및 유저 권한' 카테고리의 다른 글

umask  (0) 2023.09.01
chgrp  (0) 2023.08.31
chown  (1) 2023.08.31
chmod  (0) 2023.08.31