ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • LINUX 소유권/허가권 부여 및 심볼릭링크 설정하는 방법
    System of Infra/Linux System 2022. 3. 8. 21:37
    반응형

    LINUX로고이미지

    LINUX 소유권/허가권 부여 및 심볼릭 링크 설정하는 방법

    [root@localhost ~]# touch test
    
    [root@localhost ~]# ls -ltr | grep -i test
    -rw-r--r--  1 root root    0  3월  5 16:19 test
    ▶ 소유권과 허가권 실습을 위한 test touch 파일을 생성해 주도록 합니다. 
    [root@localhost ~]# vi test
    327f3fhwaefa87429f28fh
    ls /var
    
    [root@localhost ~]# ls -ltr | grep -i test
    -rw-r--r--  1 root root   32  3월  5 16:22 test
    ▶ test 파일 내용에  327f3fhwaefa87429f28fh라는 텍스트 글과 함께 ls /var 명령어 한 줄을 추가합니다.
    [root@localhost ~]# ./test
    bash: ./test: 허가 거부
    ▶ test 파일을 실행할 경우 허가 거부라는 경고 메시지를 호출하게 됩니다.
    [root@localhost ~]# chmod 755 test
    
    [root@localhost ~]# ./test
    ./test: line 1: 327f3fhwaefa87429f28fh: command not found
    account  cache	db     ftp    gopher	lib    lock  mail  opt	     run    tmp
    adm	 crash	empty  games  kerberos	local  log   nis   preserve  spool
    ▶ test의 권한을 755로 변경해주고 다시 test 파일을 실행하게 되면 1 line syntax에러가 발생하게 되고 다음 shell의 한 줄인 ls /var의 명령어를 수행하여 /var 밑에 디렉터리들을 확인할 수 있습니다.
    실행된 이유를 확인하게 되면 현재 실행 권한이 없는 상태에서 755를 통해서 소유자, 그룹, 기타 사용자에 대해서 x 실행 권한을 부여했기 때문입니다.

    ★ 계정생성 권한
    소유자(user) / 그룹(Group) / 기타(Other)

    r w -            r - -              r - -

    4 2 0            4 0 0            4 0 0

      6                  4                 4 

    [root@localhost ~]# touch test2
    
    [root@localhost ~]# ls -ltr | grep -i test2
    -rw-r--r--  1 root root    0  3월  5 16:25 test2
    
    [root@localhost ~]# chmod u+x test2
    
    [root@localhost ~]# chmod g+x test2
    
    [root@localhost ~]# chmod o+x test2
    
    [root@localhost ~]# ls -ltr | grep -i test2
    -rwxr-xr-x  1 root root    0  3월  5 16:25 test2
    
    [root@localhost ~]# chmod ugo-x test2
    
    [root@localhost ~]# ls -ltr | grep -i test2
    -rw-r--r--  1 root root    0  3월  5 16:25 test2
    ▶ 반복학습을 통해서 test2라는 touch 파일을 생성합니다. 현재 퍼미션은 644로 소유자, 그룹, 기타에 대해서 실행 권한을 가지고 있지 않습니다.
    그렇다면 chmod 명령어를 통해서 u+x(소유자 실행 권한 부여), g+x(그룹 실행 권한 부여), o+x(기타 실행 권한 부여)를 통해 변경하게 되면 test2의 퍼미션은 755로 변경되게 됩니다. 반대로 -를 부여하게 되면 해당 권한에서 삭제됩니다.
    [root@localhost ~]# ls -l | grep -i test
    -rwxr-xr-x  1 root root   32  3월  5 16:22 test
    -rw-r--r--  1 root root    0  3월  5 16:25 test2
    
    [root@localhost ~]# chown centos test2
    
    [root@localhost ~]# ls -ltr | grep -i test2
    -rw-r--r--  1 centos root    0  3월  5 16:25 test2
    
    [root@localhost ~]# chgrp centos test2
    
    [root@localhost ~]# ls -ltr | grep -i test2
    -rw-r--r--  1 centos centos    0  3월  5 16:25 test2
    ▶ test2의 파일에 대한 소유자와 그룹이 현재 root로 모두 지정이 되어 있습니다. 변경을 위해서 chown 명령어를 통해 소유자 권한을 centos 계정에 부여를 하고 chgrp 명령어를 통해서 centos 그룹에 부여를 하도록 하겠습니다.
    명령어를 수행 뒤 확인을 통해 test2의 소유자와 그룹이 centos로 변경된 것을 확인할 수 있습니다.
    [root@localhost ~]# ls -ltr | grep -i test
    -rwxr-xr-x  1 root   root     32  3월  5 16:22 test
    -rw-r--r--  1 centos centos    0  3월  5 16:25 test2
    
    [root@localhost ~]# chown centos:centos test
    
    [root@localhost ~]# ls -ltr | grep -i test
    -rwxr-xr-x  1 centos centos   32  3월  5 16:22 test
    -rw-r--r--  1 centos centos    0  3월  5 16:25 test2
    ▶ chown과 chgrp의 명령어를 개별적으로 수행하지 않고 chown을 통해서 :의 옵션을 주게 되면 소유자와 그룹을 한 번에 수정할 수 있습니다.
    [root@localhost /]# mkdir linktest
    
    [root@localhost linktest]# vi basefile
    basefile
    
    [root@localhost linktest]# ln basefile hardlink
    [root@localhost linktest]# ln -s basefile softfile
    ▶ / 디렉터리에 linktest라는 디렉토리 생성 후 basefile이라는 touch 파일을 한 개 생성해 주도록 합니다. 편집기를 통해서 해당 내용에 basefile을 작성하고 저장합니다.
    이후 basefile에 ln의 명령어를 통해서 hardlink를 달아주고 반대로 -s 옵션을 통해서 basfiled을 softfile로 심볼릭 링크를 달아주도록 합니다.
    [root@localhost linktest]# ls -iltr
    202515877 -rw-r--r-- 2 root root 9  3월  8 20:58 hardlink
    202515877 -rw-r--r-- 2 root root 9  3월  8 20:58 basefile
    202515876 lrwxrwxrwx 1 root root 8  3월  8 20:58 softfile -> basefile
    ▶ basefile의 inode 값은 202515877로 고유의 ID 값을 가지고 있습니다. 이 파일을 hardlink 한 hardlink 파일을 보게 되면 inode의 값 역시 동일한 것을 확인할 수 있습니다.
    반대로 심볼릭 링크를 달아준 softfile에는 권한에 l이라는 파일 표기가 생기고 inode 값 역시 원본 파일과 다른 것을 확인할 수 있습니다.
    [root@localhost linktest]# mv basefile /
    
    [root@localhost linktest]# ls -ltr
    -rw-r--r-- 2 root root 9  3월  8 20:58 hardlink
    lrwxrwxrwx 1 root root 8  3월  8 20:58 softfile -> basefile
    
    [root@localhost linktest]# cat hardlink
    basefile
    
    [root@localhost linktest]# cat softfile
    cat: softfile: 그런 파일이나 디렉터리가 없습니다
    ▶ /linktest 디렉터리에 있는 basefile을 / 디렉터리로 옮겨주도록 합니다. 해당 파일을 옮긴 뒤 hardlink의 파일은 문제없이 실행이 되지만 softfile의 경우는 원본의 파일이 사라졌기 때문에 심볼릭 링크가 깨져버린 것을 확인할 수 있습니다.
    [root@localhost linktest]# mv /basefile .
    
    [root@localhost linktest]# ls -ltr
    
    -rw-r--r-- 2 root root 9  3월  8 20:58 hardlink
    -rw-r--r-- 2 root root 9  3월  8 20:58 basefile
    lrwxrwxrwx 1 root root 8  3월  8 20:58 softfile -> basefile
    
    [root@localhost linktest]# cat softfile
    basefile
    ▶ / 디렉토리에 있는 basefile을 원복 한 뒤 softfile을 실행하게 되면 원복과 같은 파일 내용을 확인할 수 있습니다.

     

    2022.03.02 - [System of Infra/LINUX] - LINUX 계정 생성/변경/삭제하는 방법

     

    LINUX 계정 생성/변경/삭제 하는 방법

    LINUX 계정 생성/변경/삭제하는 방법 [root@localhost /]# cat /etc/passwd | grep -i root root:x:0:0:root:/root:/bin/bash [root@localhost /]# cat /etc/shadow | grep -i root root:$6$MJwYqEVQpPMPnQyF$..

    pinetreeday.tistory.com

    2021.12.27 - [System of Infra/LINUX] - LINUX SELinux 비활성화 하는 방법

     

    LINUX SELinux 비활성화 하는 방법

    LINUX SELinux 비활성화하는 방법 [root@localhost /]# sestatus SELinux status: enabled SELinuxfs mount: /sys/fs/selinux SELinux root directory: /etc/selinux Loaded policy name: targeted Current mo..

    pinetreeday.tistory.com

     

    PS. 포스팅의 내용은 제 기준으로 작성한 것이기 때문에 참고해서 보시면 감사하겠습니다.

    포스팅 과정의 오류 및 오타 그리고 궁금한 점에 대해서는 댓글 남겨주세요.

    반응형

    댓글

Designed by Tistory.