반응형
터미널 프롬프트에 새로운 파일과 디렉토리를 생성하고 ls -l 을 입력하게 되면 drwxr-xr-x 이나 -rw-r--r-- 와 같은 파일 권한이 나타난다. 이 표현의 첫 번째 시작인 - 와 d는 각각 not directory와 directory, 즉 폴더인지 파일인지를 나타낸다. 이어지는 r, w, x는 각각 read permission, write permission, execute permission으로 읽기 권한, 쓰기 권한, 실행 권한을 나타낸다. 여기서 rwx는 총 3번이 반복되는데 첫 번째는 소유자의 권한, 두 번째는 다른 사용자 그룹의 권한, 세 번째는 그 외 나머지 user의 권한을 나타낸다.
1. user, group, and other
- user: user은 파일의 소유자이다. 기본적으로 파일을 만든 사람이 소유자가 된다.
- group: group에는 여러 user이 포함될 수 있다. 그룹에 속한 모든 user은 파일에 대한 동일한 group 엑세스 권한을 갖는다.
- other: 파일에 대한 엑세스 권한이 있는 다른 user이다. 즉 파일을 만들지 않은 다른 모든 user을 의미한다. 따라서 other 권한을 설정하면 해당 권한을 global 권한으로 설정했다고 볼 수 있다.
2. chmod: 권한을 변경하는 명령어
명령어 chmod 로 권한을 변경하는 방식은 두 가지가 있다.
- 첫 째, 더하기(+), 빼기(-), 할당(=)과 액세스 유형을 표기해서 변경하는 Symbolic method
- 둘째, rwx를 3 bit로 해석해서 숫자 3자리로 권한을 표기해서 변경하는 Absolute form
2-1. Symbolic method
Access class | Operator | Access Type |
u (user) | + (add access) | r (read) |
g (group) | - (remove access) | w (write) |
o (other) | = (set exact access) | x (execute) |
a (all : u, g and o) |
chmod g-r filename // group의 read permission 제거
chmod o+w filename // other의 write permission 추가
chmod u+x filename // user의 execute permission 추가
chmod a=rw hello.js // -rw-rw-rw-
chmod u= hello.js // ----rw-rw-
chmod a+rx hello.js // -r-xrwxrwx
chmod go-wx hello.js // -r-xr--r--
chmod a= hello.js // ----------
chmod u+rwx hello.js // -rwx------
2-2. Absolute form
Permission | Number |
Read (r) | 4 |
Write (w) | 2 |
Execute (x) | 1 |
만약 user은 rwx로, group 과 other 은 r--로 권한 변경을 하려면 다음과 같다.
// u=rwx (4 + 2 + 1 =7), go=r (4 + 0 + 0 = 4)
chmod 744 hello.js // -rwxr--r--
* Absoulte form에서 사용하는 숫자 표
# | sum | rwx | Permission |
7 | 4(r) + 2(w) + 1(x) | rwx | read, write and execute |
6 | 4(r) + 2(w) + 0(-) | rw- | read and write |
5 | 4(r) + 0(-) + 1(x) | r-x | read and execute |
4 | 4(r) + 0(-) + 0(-) | r-- | read only |
3 | 0(-) + 2(w) + 1(x) | -wx | write and execute |
2 | 0(-) + 2(w) + 0(-) | -w- | write only |
1 | 0(-) + 0(-) + 1(x) | --x | execute only |
0 | 0(-) + 0(-) + 0(-) | --- | none |
반응형
'💻 개발자 > 🗄 Linux' 카테고리의 다른 글
[Linux] 기본 명령어 2 (0) | 2021.04.13 |
---|---|
[Linux] 기본 명령어 1 (0) | 2021.04.13 |