파일 구조 및 퍼미션

2022. 10. 19. 17:46리눅스

파일 구조 및 종류

실습)

[root@linux1 ~]# ls ‐l *.cfg
‐rw‐‐‐‐‐‐‐. 1 root root 1720  8월 30 16:33 anaconda‐ks.cfg
[root@linux1 ~]# ls ‐al | grep ^d
dr‐xr‐x‐‐‐.  6 root root 248  9월 7 17:05 .
dr‐xr‐xr‐x. 18 root root 237  9월 6 15:54 ..
drwxr‐xr‐x   3 root root 18  9월 7 10:47 .cache
drwxr‐xr‐x   3 root root 18  9월 7 10:47 .config
drwx‐‐‐‐‐‐ 2 root root 29  9월 7 10:47 .ssh
[root@linux1 ~]# cd /dev
[root@linux1 dev]# ls ‐l sd*
brw‐rw‐‐‐‐ 1 root disk 8, 0  9월 14 09:55 sda
brw‐rw‐‐‐‐ 1 root disk 8, 1  9월 14 09:55 sda1
brw‐rw‐‐‐‐ 1 root disk 8, 2  9월 14 09:55 sda2
[root@linux1 dev]# ls ‐l vcs
crw‐rw‐‐‐‐ 1 root tty 7, 0  9월 14 09:55 vcs
[root@linux1 dev]# ls ‐l stderr
lrwxrwxrwx 1 root root 15  9월 14 09:55 stderr ‐> /proc/self/fd/2

 

 

퍼미션

 rwx 8진수 표기

 rwx r-x r-x  :  755 

 111 101 101 : 7 5 5

 rwx r-- r-- :  744

 111 100 100 : 7 4 4

 

 

퍼미션 제어

 

chmod
 - 퍼미션 수정 명령
# chmod  [옵션]  [퍼미션 ]  [파일]

 

옵션
‐R  : 디렉토리인 경우 하위 디렉토리와 파일까지 수정

# chmod  755  a.txt
# chmod  ‐R 750  aa/

 

대상 : u(user), g(group), o(other), a(all)
operator : +(추가), ‐(삭제), =(변경하지 않음)
퍼미션 : r,w,x,s,t


# chmod  ‐R  755  ./a/ (rwxr‐xr‐x)
# chmod o+x,g‐x  a.txt
# chmod g+wx, o‐w, o+x a.txt

 

suid와 sgid, sticky bit

 - 추가된 퍼미션으로 실행 및 삭제 권한을 보완한다.

 

suid, sgid

 - 실행 파일에만 적용

 - 파일이 실행된 프로세스는 실행한 사용자 소유로 실행 권한 부여

 - suid, sgid를 설정한 파일의 프로세스는 소유자나 그룹 소유자의 ID로 실행
 - 실행 권한에 s로 명시된다.
suid : 4000, u+s
sgid : 2000, g+s    

 

Ex) passwd
Passwd 명령은 /etc/passwd, /etc/shadow 와 같은 root 소유자 파일을 변경함으로 실행 시에 파일 소유자인 root 권한으로 실행

 

sticky bit

 - 파일에 대해서 퍼미션과 관계없이 소유자만 삭제 가능하게 할 때 디렉토리에 other 권한을 제한한다.
 ‐ Other을 대상으로 설정한다.
 ‐ 모든 권한 허가가 가능하지만 삭제는 소유자만 가능하다.
 ‐ 1000 : o+t

 

suid(4), sgid(2), stick bit(1)

 - suid와 sgid는 user와 group 퍼미션에 s로 표시되고
 - stichy bit는 other 퍼미션에 t로 표시된다.
  7777  : rwsrwsrwt
  4777  :  rwsrwxrwx  (u+s)
  2777  :  rwxrwsrwx  (g+s)
  1777  :  rwxrwxrwt  (o+t)

 

실습)

[root@linux1 ~]# echo 11 > a.txt
[root@linux1 ~]# ls ‐al a.txt
‐rw‐r‐‐r‐‐ 1 root root 3  9월 14 11:16 a.txt
[root@linux1 ~]# chmod 755 a.txt
[root@linux1 ~]# ls ‐al a.txt
‐rwxr‐xr‐x 1 root root 3  9월 14 11:16 a.txt
[root@linux1 ~]# chmod g‐x,o‐x a.txt
[root@linux1 ~]# ls ‐al a.txt
‐rwxr‐‐r‐‐ 1 root root 3  9월 14 11:16 a.txt
[root@linux1 ~]# chmod a‐x a.txt
[root@linux1 ~]# ls ‐al a.txt
‐rw‐r‐‐r‐‐ 1 root root 3  9월 14 11:16 a.txt
[root@linux1 ~]# chmod u+s,o+t a.txt
[root@linux1 ~]# ls ‐al a.txt
‐rwSr‐‐r‐T 1 root root 3  9월 14 11:16 a.txt

 

chown, chgrp

 - 소유자 또는 그룹소유자 변경
# chown  [‐R]  [유저명]  [대상]
# chown  [‐R]  [유저명].[그룹명]  [대상] ‐ 비표준명령
# chgrp    [‐R]  [그룹명]  [대상]

 

실습)

[root@linux1 ~]# ls ‐al a.txt
‐rw‐r‐‐r‐‐ 1 root root 3  9월 14 11:16 a.txt
[root@linux1 ~]# chown st01 a.txt
[root@linux1 ~]# ls ‐al a.txt
‐rw‐r‐‐r‐‐ 1 st01 root 3  9월 14 11:16 a.txt
[root@linux1 ~]# chgrp st a.txt
[root@linux1 ~]# ls ‐al a.txt
‐rw‐r‐‐r‐‐ 1 st01 st 3  9월 14 11:16 a.txt
[root@linux1 ~]# chown root.root a.txt
[root@linux1 ~]# ls ‐al a.txt
‐rw‐r‐‐r‐‐ 1 root root 3  9월 14 11:16 a.txt
[root@linux1 ~]# chown .st a.txt
[root@linux1 ~]# ls ‐al a.txt
‐rw‐r‐‐r‐‐ 1 root st 3  9월 14 11:16 a.txt

 

기본 퍼미션 설정

 - 파일이 생성될 때 퍼미션중에 제외될 퍼미션을 지정

 - 기본 umask는 022(0022)
 - 디렉토리 퍼미션 : 755(0755),  파일 퍼미션 : 644(0644)

 

umask 명령
• umask 확인
# umask
• umask 변경
# umask [제외할 퍼미션]
# umask 077(0077)  
• /etc/profile 에 설정된다.
• /etc/profile, ~/.bash_profile을 이용해서 변경 가능하다.

'리눅스' 카테고리의 다른 글

네트워크  (0) 2022.10.20
파일시스템 및 파티션  (0) 2022.10.20
사용자 관리  (0) 2022.10.19
리눅스 기초명령어 3(tar, gzip, bzip, clock, date, rdate)  (0) 2022.10.19
VI 편집기  (0) 2022.10.18