Linux/Read, Write, Execute

user, group, and other

테오구 2021. 11. 8. 15:48
728x90

user:

  • user는 파일의 소유자입니다. 기본적으로 파일을 만든 사람이 소유자가 됩니다. 따라서 user를 소유자라고 하기도 합니다.

group:

  • group에는 여러 user가 포함될 수 있습니다. 그룹에 속한 모든 user는 파일에 대한 동일한 group 액세스 권한을 갖습니다.
  • 많은 사람이 파일에 액세스해야 하는 프로젝트가 있다고 가정합니다.
  • 각 user에게 일일이 권한을 할당하는 대신에 모든 user를 group에 추가하고, 파일에 group 권한을 할당할 수 있습니다.

other:

  • 파일에 대한 액세스 권한이 있는 다른 user입니다. 파일을 만들지 않은 다른 모든 user를 의미합니다. 따라서 other 권한을 설정하면, 해당 권한을 global 권한 설정이라고 볼 수도 있습니다.

chmod: 권한을 변경하는 명령어

명령어 chmod 폴더나 파일의 읽기, 쓰기, 실행 권한을 변경할 수 있습니다.

OS에 로그인한 사용자와, 폴더나 파일의 소유자가 같을 경우에 명령어 chmod 로 폴더나 파일의 권한을 변경할 수 있습니다.

 

더하기(+), 빼기(-), 할당(=)과 액세서 유형을 표기해서 변경하는 Symbolic method입니다.

rwx를 3 bit로 해석하여, 숫자 3자리로 권한을 표기해서 변경하는 Absolute form입니다.

 

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 # removes read permission from group
chmod g+r filename # adds read permission to group
chmod g-w filename # removes write permission from group
chmod g+w filename # adds write permission to group
chmod g-x filename # removes execute permission from group
chmod g+x filename # adds execute permission to group
chmod o-r filename # removes read permission from other
chmod o+r filename # adds read permission to other
chmod o-w filename # removes write permission from other
chmod o+w filename # adds write permission to other
chmod o-x filename # removes execute permission from other
chmod o+x filename # adds execute permission to other
chmod u+x filename # adds execute permission to user

 

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------

액세스 클래스와 연산자, 액세스 타입을 모두 기억해야만 Symbolic method를 이용해 권한을 변경할 수 있습니다.

Absolute form은 숫자 7까지 나타내는 3 bits의 합으로 표기합니다.

사용자, 그룹, 또는 다른 사용자나 그룹마다 rwx 가 나타나고, 각 영역의 boolean 값으로 표기할 수 있습니다.

 

Read (r) 4
Write (w) 2
Execute (x) 1

 

만약, user는 rwx 를, group과 other은 r-- 로 권한을 변경하려고 한다면, 위 표에 나와있는 숫자의 합을 user, group, other 순으로 입력하여 사용합니다.

# u=rwx (4 + 2 + 1 = 7), go=r (4 + 0 + 0 = 4)
chmod 744 helloworld.js # -rwxr--r--

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

 

728x90

'Linux > Read, Write, Execute' 카테고리의 다른 글

Read, Write, Execute 권한  (0) 2021.11.08