linux 는 NOS
network operating systems
multi-user systems
여러사람이 쓰기때문에 관리가 필요하다
리눅스는 확장자 개념이 없다
고로 권한으로 관리한다
일단 커멘드창을 이용하여 폴더, 파일을 하나씩 만들고
ls -l
명령어를 입력해보면
다음과 같은 화면이 나온다
가장 왼쪽표현을 살펴보자
-rw-r--r--
drwxr-xr-x
가장 앞쪽의 -,d 로 표기된것은 각각
- : not directory (file)
d : directory
이어지는 r,w,e는
r : read permission (읽기 권한)
w : write permission (쓰기 권한)
x : execute permission (실행 권한)
r, w, x가 3번 반복해서 나타나는 이유는
소유주(own), 소유그룹(group), 나머지사람들(others)에 대한 권한을 차례대로 나타내고있기 때문이다.
user, group, and other
user : 파일의 소유자. 기본적으로 파일을 만든 사람이 소유자가 됨. 따라서 소유주(own)라고도 부름
group : 여러 user가 포함될 수 있음. 그룹에 속한 모든 user는 파일에 대한 동일한 group 액세스 권한을 갖는다. 여러사람들이 파일에 액세스해야하는 프로젝트를 한다고할때, 일일이 각사람에게 권한을 할당하지않고 user들을 group에 추가한뒤, 파일에 group권한을 할당하면 된다.
other : 소유주, 소유그룹을 제외한 다른 user들을 뜻한다. global 권한 설정이라고도 볼 수 있다.
chmod
: 권한을 변경하는 명령어
폴더나 파일의 r, w, e 권한을 변경할 수 있다.
명령어 chmod로 권한을 변경하는 방식에는 두가지가 있다
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 명령어 뒤에 액세스 클래스, 연산자, 액세스 타입 순으로 입력한다
chmod u-r filename # removes read permission from user
chmod g+r filename # adds read permission to group
chmod o-w filename # removes write permission from other
chmod a+w filename # adds write permission to all
// 입력 결과
chmod a=rw helloworld.js # -rw-rw-rw-
chmod u= helloworld.js # ----rw-rw-
chmod a+rx helloworld.js # -r-xrwxrwx
chmod go-wx helloworld.js # -r-xr--r--
chmod a= helloworld.js # ----------
chmod u+rwx helloworld.js # -rwx------
2. Absolute form
: 숫자 7까지 나타내는 3bits의 합으로 표기한다
Permission | Number |
Read (r) | 4 (2^2) |
Write (w) | 2 (2^1) |
Execute (x) | 1 (2^0) |
<사용예시>
r, w, e의 숫자의 합을 user, group, other 순으로 입력한다
chmod 744 helloworld.js # -rwxr--r--
chmod 655 helloworld.js # -rw-r-xr-x
Absolute 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 |
🤟🏻 알아두기
폴더에 Execute권한이 없을경우는 폴더안으로 진입이 불가하다는 뜻 !
폴더에 Write권한을 주면 폴더안에있는 파일,폴더의 생성,삭제,수정이 가능하다는 뜻 !
( 무시무시한 권한임 : root가 소유주인 파일, 폴더도 수정, 삭제 가능)
'Linux' 카테고리의 다른 글
환경변수 사용법 (0) | 2022.03.01 |
---|---|
Linux 관리자 권한과 경로 (0) | 2021.11.18 |
Linux CLI 기본 명령어 (0) | 2021.11.17 |
댓글