su 서비스계정 : 현재 적용되어 있는 환경변수로 서비스계정을 로그인한다.
[jslee11g@localhost test5]$ pwd
/home/jslee11g/test5
[jslee11g@localhost test5]$ su root
Password:
[root@localhost test5]# pwd
/home/jslee11g/test5
[root@localhost test5]# su oracle
[oracle@localhost test5]$ pwd
/home/jslee11g/test5
# 단, 어떠한 계정으로 접속을 하더라도 해당 디렉터리에 대한 권한이 없는 계정일 경우
# 디렉터리 내에 대한 활동에 제한이 된다.
[jslee11g@localhost ~]$ ls -l
drwxrwx--- 2 jslee11g jslee11g 6 May 16 11:07 test5
[jslee11g@localhost ~]$ cd test5
[jslee11g@localhost test5]$ pwd
/home/jslee11g/test5
# other에 권한이 없을 경우 su를 통해 다른 계정이 들어가지더라도 활동에 제한이 있다.
[jslee11g@localhost test5]$ su oracle
[oracle@localhost test5]$ ls
ls: cannot open directory .: Permission denied
[oracle@localhost test5]$ ls -l
ls: cannot open directory .: Permission denied
[oracle@localhost test5]$ pwd
/home/jslee11g/test5
[oracle@localhost test5]$ cd ..
[oracle@localhost jslee11g]$ cd test5
bash: cd: test5: Permission denied
su - 서비스계정 : 서비스계정마다 등록되어 있는 환경변수로 변경 적용되어 로그인 된다.
[jslee11g@localhost test4]$ pwd
/home/jslee11g/test4
[jslee11g@localhost test4]$ su - oracle
Password:
Last login: Tue May 16 11:11:05 KST 2023 on pts/0
[oracle@localhost ~]$ pwd
/home/oracle
r : 읽기 - 4
w : 쓰기 - 2
x : 실행 - 1
[oracle@localhost ~]$ ls -tl
total 8
drwxr-xr-x 2 oracle dba 6 May 15 14:58 test4
-rw-r--r-- 1 root root 5 May 15 14:55 test3.sh
-rw-r--r-- 1 oracle dba 8 May 15 14:55 test1.sh
drwxr-xr-x 2 root root 6 May 15 14:45 test2
drwxr-x--- 3 oracle dba 18 Apr 24 14:45 oradiag_oracle
test4 디렉터리를 통해 퍼미션 확인하기
d : d는 디렉터리
2 : 링크카운터 : 해당하는 데이터블록에 연결되어진 파일의 개수
rwxr-x-r-x : 755 (7 : 파일의소유자 권한, 5 : 그룹 소유자 권한, 5 : other 일반사용자에게 부여된 권한)
oracle : 파일의 소유자
dba : 파일의 그룹
6 : 파일 사이즈
시간 : 최종 업데이트된 시간
test4 : 파일 이름(현재는 디렉터리)
test3.sh 파일을 통해 퍼미션 확인하기
- : 일반파일
rw-r--r-- : 644
root : 파일의 소유자
root(두번째) : 파일의 그룹
5 : 파일 사이즈
시간 : 최종 업데이트된 시간
test3.sh : 파일 이름
허가권 변경 $ chmod 기호 문자
-R : 특정 디렉터리 내의 파일과 디렉터리에 대한 모든 허가권 변경
u : 사용자
g : 그룹
o : other
a : all - 사용자 그룹 other
+ : 더하기
- : 빼기
= : 설정 (궁금증 더하기 빼기를 안하고 그냥 이것만 사용해도 되지 않을까?
chmod a 의 예시
[root@localhost jslee11g]# ls -l
total 0
-rw-r--r-- 1 root root 0 May 15 13:15 test1.sh
[root@localhost jslee11g]# chmod a+rwx test1.sh
[root@localhost jslee11g]# ls -l
total 0
-rwxrwxrwx 1 root root 0 May 15 13:15 test1.sh
chmod g=의 예시
[root@localhost jslee11g]# ls -l
total 0
-rwxrwxrwx 1 root root 0 May 15 13:15 test1.sh
[root@localhost jslee11g]# chmod g=wr test1.sh
[root@localhost jslee11g]# ls -l
total 0
-rwxrw-rwx 1 root root 0 May 15 13:15 test1.sh
other의 예시
[jslee11g@localhost ~]$ cat test2.sh
echo test11
[jslee11g@localhost ~]$ sh test2.sh
test11
ls -l을 통해 정보를 확인시 소유주와 상관 없는 다른 그룹이 권한을 가지고 있을때, 해당 그룹 계정들은 이용할 수 있을까?
# 현재 dir1-1 디렉터리의 권한은 775이며 root 그룹과 root 소유자를 가지고 있다.
[root@localhost home]# ls -l
total 0
drwxrwxr-x 2 root root 38 May 16 09:15 dir1-1
# test1.sh의 경우 jslee11g 그룹과 jslee11g 계정에게 소유권을 준 상황이며
# test2.sh는 dba그룹에 소유권을 준상황에서 dba그룹에 속하지 않은 jslee11g에게 소유자 권한을 준 상황이다.
[root@localhost home]# cd dir1-1
[root@localhost dir1-1]# ls -l
total 4
-rwxr--rw- 1 jslee11g jslee11g 0 May 15 13:17 test1.sh
-rw-r--r-- 1 jslee11g dba 24 May 16 09:15 test2.sh
root 계정이 아닌 jslee11g 그룹에 속한 jslee11g계정으로 접속 후 root 디렉터리 안에 있는 test1.sh과 test2.sh 파일을 건드릴 수 있는지 확인해보려고 한다.
[jslee11g@localhost home]$ ls -l
total 0
drwxrwxr-x 2 root root 38 May 16 09:15 dir1-1
drwxrwxrwx. 4 jslee11g jslee11g 176 May 15 18:01 jslee11g
drwx------. 7 oracle dba 240 May 15 16:44 oracle
[jslee11g@localhost home]$ cd dir1-1
# 해당 디렉터리에 들어가는 것은 전혀 문제가 되지 않는다.
# 이유는 dir1-1의 775에서 other를 살펴보면 읽고 실행이 가능하기 때문
# test1.sh와 test2.sh 모두 계정 소유주가 jslee11g로 되어 있으며
# 각각 7과 6으로 등록이 되어 있어 읽기 쓰기가 가능하다.
[jslee11g@localhost dir1-1]$ ls -l
total 4
-rwxr--rw- 1 jslee11g jslee11g 0 May 15 13:17 test1.sh
-rw-r--r-- 1 jslee11g dba 24 May 16 09:15 test2.sh
[jslee11g@localhost dir1-1]$ cat test1.sh
jslee11g test1.sh
[jslee11g@localhost dir1-1]$ vi test1.sh
[jslee11g@localhost dir1-1]$ cat test1.sh
jslee11g test1.sh
jslee11g login
[jslee11g@localhost dir1-1]$ cat test2.sh
test2.sh
echo test2.sh
[jslee11g@localhost dir1-1]$ cat test2.sh
test2.sh
echo test2.sh
jslee11g login
그렇다면 다른 계정으로 들어와 test1.sh과 test2.sh를 읽기 혹은 수정을 한다면?
[oracle@localhost dir1-1]$ ls -l
total 8
-rwxr--rw- 1 jslee11g jslee11g 33 May 16 09:50 test1.sh
-rw-r--r-- 1 jslee11g dba 38 May 16 09:51 test2.sh
[oracle@localhost dir1-1]$ cat test1.sh
jslee11g test1.sh
jslee11g login
[oracle@localhost dir1-1]$ vi test1.sh
[oracle@localhost dir1-1]$ cat test1.sh
jslee11g test1.sh
jslee11g login
oracle login
# test1.sh 의 경우 소유자와 소유그룹이 jslee11g로 되어 있다 한들
# other에서 rw-의 권한으로 인해 진행이 가능해진다.
# test2.sh 파일에 대한 oracle의 권한은 dba 현재 그룹에서도 r--, other에서도 r--이 되어 있으니
# 읽기는 가능하나 쓰기 기능은 불가능하다.
[oracle@localhost dir1-1]$ cat test2.sh
test2.sh
echo test2.sh
jslee11g login
[oracle@localhost dir1-1]$ vi test2.sh
# 이때 wq!를 활용해 강제 저장을 하고자 해도 권한이 없어서 진행이 불가능하다.
# 그렇다면 그룹에게만 권한을 줬을때는?
# 현재 상황은 oracle 그룹이 속한 dba에 대해서는 모든 권한을 부여한 상황이지만
# 소유주가 그룹과 관련이 없는 계정이다. other또한 읽기만 가능할때 여부는?
[oracle@localhost dir1-1]$ ls -l
total 8
-rwxr--rw- 1 jslee11g jslee11g 46 May 16 09:54 test1.sh
-rwxrwxr-- 1 jslee11g dba 38 May 16 09:51 test2.sh
# 확인 결과 그룹소유가 권한이 있다면 소유주가 달라도 변경이 가능하다.
[oracle@localhost dir1-1]$ cat test2.sh
test2.sh
echo test2.sh
jslee11g login
[oracle@localhost dir1-1]$ vi test2.sh
[oracle@localhost dir1-1]$ cat test2.sh
test2.sh
echo test2.sh
jslee11g login
oracle dba login
결과를 도출하자면, 그룹에게 모든 권한을 부여한다면 그룹내 모든 계정들은 이용할 수 있다는 것을 알게 되었다.
어떠한 계정이 파일에 허가권을 가지고 있지만, 그 파일을 담고 있는 디렉터리에 허가권이 없다면 사용불가에 대한 예시
# /home/dir1-2 에서 770으로 oracle 계정과 dba 그룹에게만 권한을 준 상황
[root@localhost home]# ls -l
total 0
drwxrwxr-x 2 root root 38 May 16 09:42 dir1-1
drwxrwx--- 3 oracle dba 20 May 16 10:12 dir1-2
drwxrwxrwx. 4 jslee11g jslee11g 176 May 16 09:51 jslee11g
drwx------. 7 oracle dba 240 May 16 10:02 oracle
# /home/dir1-2/dir2-1 의 경우는 755의 권한을 준 상황
[root@localhost home]# cd dir1-2
[root@localhost dir1-2]# ls -l
total 0
drwxr-xr-x 2 oracle dba 22 May 16 10:13 dir2-1
# 마지막 /home/dir1-2/dir2-1/test1.sh 에는 jslee11g 소유자와 jslee11g 소유그룹 권한이 부여된 상황이다.
[root@localhost dir1-2]# cd dir2-1
[root@localhost dir2-1]# ls -l
total 4
-rwxrwxrwx 1 jslee11g jslee11g 9 May 16 10:13 test1.sh
# 처음 디렉터리에 oracle:dba 권한만 부여되고 other는 권한이 없는 상황에서 디렉터리 안에
# 다른 소유주와 다른 소유그룹자일 경우에는?
[jslee11g@localhost home]$ cd dir1-2
-bash: cd: dir1-2: Permission denied
[jslee11g@localhost home]$ cd /home/dir1-2/dir2-1
-bash: cd: /home/dir1-2/dir2-1: Permission denied
[jslee11g@localhost home]$ cd /home/dir1-2/
-bash: cd: /home/dir1-2/: Permission denied
# 아무리 하위 폴더 안에 있는 파일 권한이 jslee11g 소유자와 jslee11g 소유그룹 권한을 가지고 있더라도
# 상위 디렉터리에 다른 계정인 770으로서 oracle 소유자와 dba 소유그룹으로 other에 아무런 권한이 없다면
# jslee11g 계정자 jslee11g 소유그룹은 /home/dir1-2/dir2-1/test1.sh을 사용할 수 없다.
사용자 및 그룹 소유권변경 $ chown
소유권을 변경하고자 한다면 root 계정으로만 가능하다.
$ chown 서비스계정:서비스그룹 파일(or 디렉터리)
-R 을 추가하면 해당 디렉터리 이하 모든 파일 및 디렉터리에 대해 적용된다.
# root 계정이 아닌 다른 계정으로 접속 후 소유권 변경을 요청했을때 적용 불가능하다는 출력문
[oracle@localhost ~]$ chown root test4
chown: changing ownership of ‘test4’: Operation not permitted
# 계정명만 작성시 계정 소유권만 적용됨
[root@localhost oracle]# ls -l
drwxr-xr-x 2 root root 6 May 15 14:45 test2
[root@localhost oracle]# chown jslee11g test2
[root@localhost oracle]# ls -l
drwxr-xr-x 2 jslee11g root 6 May 15 14:45 test2
# 계정명: 만 작성시 계정 소유권만 적용됨
[root@localhost oracle]# ls -l
drwxr-xr-x 2 jslee11g root 6 May 15 14:45 test2
[root@localhost oracle]# chown root: test2
[root@localhost oracle]# ls -l
drwxr-xr-x 2 root root 6 May 15 14:45 test2
# :그룹 만 작성해도 그룹 소유권만 적용됨
[root@localhost oracle]# ls -l
-rw-rw-r-- 1 root root 10 May 15 16:32 test5
[root@localhost oracle]# chown :dba test5
[root@localhost oracle]# ls -l
-rw-rw-r-- 1 root dba 10 May 15 16:32 test5
# 단, 없는 계정이거나 없는 그룹일 경우에 적용이 안된다.
# 또한 계정은 존재하나 그룹이 존재하지 않는 경우 소유권 변경은 모두 불가능하다.
[root@localhost oracle]# chown jslee:jslee11g test2
chown: invalid user: ‘jslee:jslee11g’
[root@localhost oracle]# chown jslee11g:jslee test2
chown: invalid group: ‘jslee11g:jslee’
'OS' 카테고리의 다른 글
리눅스 실습하기 방화벽(firewalld)-04{2023년05월17일} (0) | 2023.05.17 |
---|---|
리눅스 실습하기-02{2023년05월16일} (0) | 2023.05.16 |
리눅스 명령어 {2023년05월12일, 15일} (1) | 2023.05.15 |
절대경로 상대경로 구분 {2023년05월12일} (0) | 2023.05.12 |
윈도우 공부하기-03{2023년05월09일} (0) | 2023.05.09 |