08_권한
1. 폴더/파일에서 권한 표시가 있음
- 권한 : 소유권과 관계가 있음
- 기본 규칙 : 작성한 사람이 소유권을 가짐, 쓰기(write), 읽기(read), 실행(execute) 3가지 권한을 모두 할 수 있음
- 권한 : 작성자(소유자, user), 작성자그룹(group), 다른사람들(other)로 나뉨
- root : 슈퍼계정(사용자, 관리자계정), 회사에서 root 계정 가진사람, 전산실 관리자(1-2명)
- 리눅스에서는 모든 명령어, 장치(마우스, 키보드) 들이 모두 파일로 이루어져있음
예제 1) /bin/cat 이라는 명령어 파일을 상세보기 하세요
oracle@488a2397e634:/bin$ ls -l cat
-rwxr-xr-x 1 root root 35064 Jan 18 2018 cat
oracle@488a2397e634:/bin$
# 해석
oracle@488a2397e634:/bin$ ls -l cat
-rwxr-xr-x 1 root root 35064 Jan 18 2018 cat
[작성자] [작성자그룹]
-rwxr-xr-x : -rwx r-x r-x
[작성자] [그룹] [다른사람들]
r : read(읽기), w : write(쓰기), x : execute(실행)
oracle@488a2397e634:/bin$
2. 파일의 권한 변경 #1 : chmod [사용자(u,g,o)][+/-][권한(r,w,x)] 파일명
chmod : change mode
사용자(u,g,o) u : user, g : group, o : other
+/- + : 권한주기, - : 권한뺏기
권한(r,w,x) r : read, w : write, x : execute
예제 2) work 폴더에서 newfile1을 만들고, user(사용자)에 대해 읽기 권한뺏기를 하세요
oracle@488a2397e634:~$ ls -l // 상세보기
total 4
-rw-r--r-- 1 oracle dba 0 Feb 22 06:23 newfile1
drwxr-xr-x 4 oracle dba 4096 Feb 22 00:40 work
oracle@488a2397e634:~$
oracle@488a2397e634:~$ chmod u-r newfile1 // 권한뺏기
oracle@488a2397e634:~$ ls
newfile1 work
oracle@488a2397e634:~$ ls -l // 상세보기
total 4
--w-r--r-- 1 oracle dba 0 Feb 22 06:23 newfile1
drwxr-xr-x 4 oracle dba 4096 Feb 22 00:40 work
oracle@488a2397e634:~$ cat newfile1
cat: newfile1: Permission denied
oracle@488a2397e634:~$
연습 1) newfile2 만들고(touch) user 에대해서 읽기 권한을 뺒기하세요
oracle@488a2397e634:~$ touch newfile2 // newfile2 만들기
oracle@488a2397e634:~$ ls // 목록 보기
newfile1 newfile2 work
oracle@488a2397e634:~$ ls -l // 목록 상세보기
total 4
--w-r--r-- 1 oracle dba 0 Feb 22 06:23 newfile1
-rw-r--r-- 1 oracle dba 0 Feb 22 06:32 newfile2
drwxr-xr-x 4 oracle dba 4096 Feb 22 00:40 work
oracle@488a2397e634:~$ chmod u-r newfile2 // 권한 뺏기
oracle@488a2397e634:~$ ls -l // 목록 상세보기
total 4
--w-r--r-- 1 oracle dba 0 Feb 22 06:23 newfile1
--w-r--r-- 1 oracle dba 0 Feb 22 06:32 newfile2
drwxr-xr-x 4 oracle dba 4096 Feb 22 00:40 work
oracle@488a2397e634:~$
예제 3) newfil1에 user의 읽기 권한 다시 주기
oracle@488a2397e634:~$ chmod u+r newfile1 // 권한 부여하기
oracle@488a2397e634:~$ ls -l // 목록 상세보기
total 4
-rw-r--r-- 1 oracle dba 0 Feb 22 06:23 newfile1
--w-r--r-- 1 oracle dba 0 Feb 22 06:32 newfile2
drwxr-xr-x 4 oracle dba 4096 Feb 22 00:40 work
oracle@488a2397e634:~$
연습 2) newfile2 에 user의 읽기 권한 다시 주기
oracle@488a2397e634:~$ ls -l
total 4
-rw-r--r-- 1 oracle dba 0 Feb 22 06:23 newfile1
-rw-r--r-- 1 oracle dba 0 Feb 22 06:32 newfile2
drwxr-xr-x 4 oracle dba 4096 Feb 22 00:40 work
oracle@488a2397e634:~$
3. 파일의 권한 변경 #2 : 숫자로 권한 주기/뺏기 : chmod 숫자 파일명
읽기(r) : 4, 쓰기(w) : 2, 실행(x) : 1
실행파일 : 녹색
rwx rwx rwx
[user] [group] [other]
4 4 4 => r--r--r--
2 2 2 => -w--w--w-
6 6 6 => rw-rw-rw-
7 7 7 => rwxrwxrwx
예제 3) newfile3 만들고 모든 권한 모든 사람에게 주세요 (모두 : rwx 권한을 부여하세요)
oracle@488a2397e634:~$ chmod 777 newfile3 // 숫자로 권한 부여
oracle@488a2397e634:~$ ls -l // 목록 상세보기
total 4
-rw-r--r-- 1 oracle dba 0 Feb 22 06:23 newfile1
-rw-r--r-- 1 oracle dba 0 Feb 22 06:32 newfile2
-rwxrwxrwx 1 oracle dba 0 Feb 22 07:08 newfile3 // 실행파일 : 녹색
drwxr-xr-x 4 oracle dba 4096 Feb 22 00:40 work
oracle@488a2397e634:~$
'Linux' 카테고리의 다른 글
#41 [docker] 컨테이너 활용 : 접속 run, 유틸리티 프로그램 설치, ifconfig eth0, attach, exec -it (0) | 2024.02.23 |
---|---|
#40 [docker] 컨테이너 (0) | 2024.02.22 |
#40 [Linux] 셀, 셀변수, 프롬프트, echo $SHELL, echo $PATH, locale -a, 환경설정 파일 (0) | 2024.02.22 |
#40 [Linux] vi 에디터 : 명령어모드 / 편집모드 (0) | 2024.02.22 |
#39 [Linux] 설치, 계정만들기, 기본명령어, 폴더/파일 명령어, 파일/컨트롤 (0) | 2024.02.21 |