Linux TIL 05

Nabang Kim·2021년 8월 23일

Linux

목록 보기
5/6
post-thumbnail

2021년 8월 23일에 작성된 문서 1번 입니다.
linux 배운 내용을 정리했습니다.



Read, Write, Execute 권한

폴더인지 파일인지 확인하기

// 폴더와 파일을 생성

mkdir linux
nano helloworld.js

// linux 폴더를 생성하고, helloworld.js 파일을 생성
  • 위의 명령어로 폴더 하나와 파일 하나를 각각 생성했다.
  • 이번에는 명령어 ls -l 을 프롬프트에 입력하고 Enter(엔터 키)를 누르면 다음과 같은 출력을 만날 수 있다.

image

ls -l 을 입력하면 터미널에 나타나는 출력.
username은 사용자 이름.

  • 파일 helloworld.js : -rw-r--r--
  • 폴더 linux : drwxr-xr-x

  • - : not directory (파일)
  • d : directory (폴더)
  • r : read permission (읽기 권한)
  • w : write permission (쓰기 권한)
  • x : execute permission (실행 권한)

  • 3번에 걸쳐 나타나는 이유 : 사용자와 그룹, 나머지에 대한 권한을 표시
  • 파일 helloworld.js의 권한 : rw-r--r--
    • 소유자는 읽기와 쓰기가 가능
    • 다른 사용자 그룹은 읽기만 가능
  • 폴더 linux의 권한 : rwxr-xr-x
    • 소유자는 읽기와 쓰기, 실행이 가능하고
    • 다른 사용자 그룹은 읽기와 실행만 가능

image



user, group, and other

user:

  • user는 파일의 소유자.
  • 기본적으로 파일을 만든 사람이 소유자.

group:

  • 여러 user가 포함될 수 있다.
  • 그룹에 속한 모든 user는 파일에 대한 동일한 group 액세스 권한을 가진다.

other:

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


chmod: 권한 변경 명령어

chmod로 폴더나 파일의 읽기, 쓰기, 실행 권한을 변경할 수 있다.

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

만약 OS에 로그인한 사용자와, 폴더나 파일의 소유자가 다를 경우에는 관리자 권한을 획득하는 명령어 sudo 를 이용해 폴더나 파일의 권한을 변경할 수 있습니다.



명령어 chmod 로 권한을 변경하는 2가지 방법.

1. Symbolic method

  • 더하기(+), 빼기(-), 할당(=)과 액세서 유형을 표기해서 변경하는 방법
  • 액세스 클래스, 연산자, 액세스 타입으로 구분한다.

Symbolic method의 구분

Access classOperatorAccess 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 뒤에 변경할 권한을 입력.
  • 액세스 클래스의 u, g, o, a를 변경할 조건에 따라 조합하여 입력
  • 연산자와 액세스 타입을 순서대로 입력.

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

// 명령어 `chmod` 를 입력한 예시와 결과

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

// symbolic method 사용 예시

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

// chmod 명령어와 symbolic method로 
// helloworld.js 파일의 권한을 변경


2. Absolute form

  • rwx를 3 bit로 해석숫자 3자리로 권한을 표기해서 변경하는 방법
  • Absolute form은 숫자 7까지 나타내는 3 bits의 합으로 표기.
  • 사용자, 그룹, 또는 다른 사용자나 그룹마다 rwx 가 나타나고, 각 영역의 boolean 값으로 표기할 수 있다.

Absolute form 구분

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

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

// chmod 명령어와 Absolute form으로 
// helloworld.js 파일의 권한을 변경

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

Absolute form에서 사용하는 숫자 (숫자별 권한)

#SumrwxPermission
74(r) + 2(w) + 1(x)rwxread, write and execute
64(r) + 2(w) + 0(-)rw-read and write
54(r) + 0(-) + 1(x)r-xread and execute
44(r) + 0(-) + 0(-)r--read only
30(-) + 2(w) + 1(x)-wxwrite and execute
20(-) + 2(w) + 0(-)-w-write only
10(-) + 0(-) + 1(x)--xexecute only
00(-) + 0(-) + 0(-)---none



Written with StackEdit.

0개의 댓글