Recent Comments
Link
Recent Posts
Today
Total
«   2025/03   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
관리 메뉴

Study Memory Work

[Linux] Permission 권한 본문

Linux (Ubuntu, macOS)

[Linux] Permission 권한

Hera Choi 2022. 9. 29. 10:14

 

모든 사용자는 이 파일을 읽을 수 있다. 이 파일의 소유자와 그룹은 파일을 쓸 수 있다.

  1. Type : 일반 파일 [-], 디렉토리 [d]
  2. Access mode : 권한
    1) Owner 권한
    2) Group 권한
    3) Other 권한 : 오너도 아닌 그룹도 아닌 모든 사용자

    * r : read 읽기, w : write 쓰기, x : excute 실행하기
  3.  
  4. 소유자 정보
    1) Owner : 소유자
    2) Group : 소유자가 속한 그룹
  5.  
  6. 생성날짜
  7. 이름

 

권한 설정/변경 하기 ::: chmod

chmod [사용자][+/-][권한종류] 파일명

//ex
chmod o-r test.txt
 

[사용자]

o : other

u : owner(User)

r : group

a : o+u+r 모든 사용자

 

[+/-]

+ : 권한추가

- : 권한회수

 

[권한 종류]

r / w / x : 읽기 / 쓰기 / 실행

 

Excute 실행 권한 ::: x

  • 실행 가능한 파일을 실행하는 권한.
  • test할 실행파일 생성

위 파일을 아래와 같이 지정한 실행 경로와 함께(bin/bash) 프로그램을 실행시키는 것은 누구나 가능하나,

$ /bin/bash hello.txt
 

현 디렉토리에서 다이렉트로 프로그램을 실행시키려면 권한이 필요하다.

$ ./hello.sh
bash: ./hello.sh: Permission denied    // 권한 없음 에러
 

 

  • 권한 설정
chmod u+x hello.sh  // hello.sh 실행파일에 대해 오너(유저)에게 실행 권한 설정

$ ./hello.sh
hello world!    // 정상 실행
 
 

위처럼 권한을 설정하면 ls -l 에서 권한이 설정된 것을 볼 수 있다.

 

 

디렉토리 권한

r : 내부 파일 및 정보 조회 권한.

w : 내부에 파일을 생성 권한.

x : 디렉토리에 접근 권한

 

 

 

chmod

출처 입력

  • 명령어 구조
$ chmod [options] mode[,mode] file1 [file2 ...]
 
  • 8진법 숫자를 이용하여 권한 한번에 설정하기
 
 
읽기 (r)
쓰기 (w)
실행 (x)
유저 (u)
4
2
1
그룹 (g)
4
2
1

other (o)
4
2
1

 

chmod 111 test.txt    // --x--x--x
chmod 222 test.txt    // -w--w--w-
chmod 333 test.txt    // -wx-wx-wx     1+2
chmod 444 text.txt    // r--r--r--
chmod 555 test.txt    // r-xr-xr-x     1+4
chmod 666 test.txt    // rw-rw-rw-     2+4
chmod 777 test.txt    // rwxrwxrwx     1+2+4
 

 

  • 알파벳으로 권한 한번에 설정
chmod a+r test.txt
chmod a-r test.txt
chmod a=rwx test.txt
chdmo a= text.txt