ㅇ리눅스 명령어 복습
1. pwd
2. touch
3. mkdir
4. rm
5. rmdir
6. alias
7. cat
8. redirection
9. more
10. head
11. wc
12. grep
13. awk
14. sort
15. uniq
16. echo
17. diff
18. find
19. tar
20. sed
21. cp
22. mv
23. chown : 파일이나 디렉토리의 소유자를 변경하는 명령어
24 chmod 명령어
파일이나 디렉토리의 권한을 변경하는 명령어
번호 | 권한 | 대표문자 | 파일 | 디렉토리 |
4 | 읽기권한 | r | 읽기, 복사 | 디렉토리에서 ls명령어 가능 |
2 | 쓰기권한 | w | 수정 | 디렉토리에서 파일 생성 가능 |
1 | 실행권한 | x | 실행 | 디렉토리에서 cd로 접근가능 |
문제97. 아래 데이터를 리눅스 서버에 root/밑으로 올리시오.
데이터 : skin.csv
[root@localhost ~]# cd /media
[root@localhost media]# ls
sf_share
[root@localhost media]# cd sf_share
[root@localhost sf_share]# ls
data8.tgz emp.txt mushrooms.csv skin.csv
dept2.txt jobs.txt reviewData2.csv wisc_bc_data.csv
[root@localhost sf_share]# mv skin.csv /root/skin.csv
문제98. skin.csv 파일에 대한 권한을 확인하시오.
[root@localhost ~]# ls -l skin.csv
-rwxrwx---. 1 root vboxsf 856 1월 24 18:32 skin.csv
- : 디렉토리인지 아닌지를 알려주는 부분, d로 나오면 디렉토리 -로 나오면 파일
rwx : 유저권한, root유저가 이 파일을 읽고(r), 쓰고(w), 실행(x) 할 수 있다는 의미
rwx : 그룹권한, root그룹에 속한 유저들dl 이 파일을 읽고(r), 쓰고(w), 실행(x) 할 수 있다는 의미
---. : 기타유저권한, ---로 나오는데 이 말은 기타 다른 유저들은 이 파일에 대해서 아무런 권한을 행사할 수 없음.
문제99. skin.csv 파일의 권한을 조정하는데 유저, 그룹, 기타유저 모두 이 파일을 읽을 수만 있도록 변경하시오.
[root@localhost ~]# chmod u-rwx,g-rwx,o-rwx skin.csv
[root@localhost ~]# ls -l skin.csv
----------. 1 root vboxsf 856 1월 24 18:32 skin.csv
[root@localhost ~]# chmod u+r,g+r,o+r skin.csv
[root@localhost ~]# ls -l skin.csv
-r--r--r--. 1 root vboxsf 856 1월 24 18:32 skin.csv
문제100. skin.csv 파일의 권한을 조정하는데 유저, 그룹, 기타유저 모두 이 파일을 읽고 쓸수 있도록 변경하시오.
[root@localhost ~]# chmod u+w,g+w,o+w skin.csv
[root@localhost ~]# ls -l skin.csv
-rw-rw-rw-. 1 root vboxsf 856 1월 24 18:32 skin.csv
# chmod u+rw,g+rw,o+rw skin.csv 이렇게 둘 다 넣어도 가능함
문제101. 다시 skin.csv 파일의 모든 권한을 다 취소하시오.
[root@localhost ~]# chmod u-rw,g-rw,o-rw skin.csv
[root@localhost ~]# ls -l skin.csv
----------. 1 root vboxsf 856 1월 24 18:32 skin.csv
문제102. 다시 유저, 그룹, 기타유저에게 읽기 권한을 부여하는데 숫자로 부여하시오.
[root@localhost ~]# chmod 444 skin.csv
[root@localhost ~]# ls -l skin.csv
-r--r--r--. 1 root vboxsf 856 1월 24 18:32 skin.csv
문제103. 이번에는 읽기과 쓰기권한을 부여하시오.
[root@localhost ~]# chmod 666 skin.csv
[root@localhost ~]# ls -l skin.csv
-rw-rw-rw-. 1 root vboxsf 856 1월 24 18:32 skin.csv
읽기권한 4 + 쓰기권한 2 = 6
문제104. 이번에는 읽기, 쓰기, 실행권한을 모두 부여하시오.
[root@localhost ~]# chmod 777 skin.csv
[root@localhost ~]# ls -l skin.csv
-rwxrwxrwx. 1 root vboxsf 856 1월 24 18:32 skin.csv
문제105. 유저에게 rwx권한을 주고, 그룹에게는 rw권한, 기타 유저에게는 실행권한만 주시오
[root@localhost ~]# chmod 761 skin.csv
[root@localhost ~]# ls -l skin.csv
-rwxrw---x. 1 root vboxsf 856 1월 24 18:32 skin.csv
# chmod u-rwx,g-rwx,o-rwx skin.csv
# chmod u+rwx,g+rw,o+x skin.csv 다 빼버린 다음에 다시 부여하는 방식으로 줘도 됨
문제106. 이번에는 숫자로 권한을 부여하시오.(위의 코드랑 동일)
문제107. 이번에는 유저에게는 읽고, 실행하는 권한을 주고, 그룹에게는 읽기, 쓰기 권한을 주고, 기타유저는 실행권한만 주시오.
[root@localhost ~]# chmod 561 skin.csv
[root@localhost ~]# ls -l skin.csv
-r-xrw---x. 1 root vboxsf 856 1월 24 18:32 skin.csv
문제108. skin.csv파일의 소유자를 oracle로 변경하시오. 그룹도 oracle로 변경하시오.
[root@localhost ~]# chown oracle:oracle skin.csv
[root@localhost ~]# ls -l skin.csv
-r-xrw---x. 1 oracle oracle 856 1월 24 18:32 skin.csv
문제109. skin.csv 파일의 권한을 소유자,그룹,기타 유저 모두 읽고,쓰고,실행할 수 있도록 하시오.
[root@localhost ~]# chmod 777 skin.csv
[root@localhost ~]# ls -l skin.csv
-rwxrwxrwx. 1 oracle oracle 856 1월 24 18:32 skin.csv
문제110. 그럼 이번에 다시 skin.csv 파일의 소유자를 root로 변경하시오. 그룹도 root로 변경하시오.
[root@localhost ~]# chown root:root skin.csv
[root@localhost ~]# ls -l skin.csv
-rwxrwxrwx. 1 root root 856 1월 24 18:32 skin.csv
ㅇ디렉토리의 소유자를 변경하는 방법
문제111. /root 밑에 test8000이라는 디렉토리를 생성하시오.
[root@localhost ~]# cd
[root@localhost ~]# mkdir test8000
[root@localhost ~]# ls -ld test8000
drwxr-xr-x. 2 root root 6 3월 14 11:13 test8000
문제112. test8000 디렉토리의 소유자를 oracle로 변경하고 그룹도 oracle로 변경하세요.
[root@localhost ~]# chown oracle:oracle test8000
[root@localhost ~]# ls -ld test8000
drwxr-xr-x. 2 oracle oracle 6 3월 14 11:13 test8000
그냥 변경할때는 -R 옵션을 안써도 됨
문제113. test8000 디렉토리의 소유자를 다시 root로 변경하고, 그룹도 root로 변경하시오.
[root@localhost ~]# chown root:root test8000
[root@localhost ~]# ls -ld test8000
drwxr-xr-x. 2 root root 6 3월 14 11:13 test8000
문제114. /root 밑에 있는 moga.csv와 moga2.csv를 /root/test8000 밑에 복사하시오.
[root@localhost ~]# cd
[root@localhost ~]# cp moga.csv ./test8000/moga.csv
[root@localhost ~]# cp moga2.csv ./test8000/moga2.csv
[root@localhost ~]# cd test8000
[root@localhost test8000]# ls
moga.csv moga2.csv
[root@localhost test8000]# ls -l *.csv
-rw-r--r--. 1 root root 432416 3월 14 11:23 moga.csv
-rw-r--r--. 1 root root 432416 3월 14 11:23 moga2.csv
[root@localhost test8000]# cd ..
[root@localhost ~]# ls -ld test8000
drwxr-xr-x. 2 root root 39 3월 14 11:23 test8000
test8000 디렉토리의 소유자도 root이고, test8000밑에 있는 csv의 소유자도 root인 것을 확인함
문제115. /root 밑에 있는 test8000 디렉토리의 소유자를 oracle로 변경하시오.
[root@localhost ~]# chown oracle:oracle test8000
[root@localhost ~]# ls -ld test8000
drwxr-xr-x. 2 oracle oracle 39 3월 14 11:23 test8000
[root@localhost ~]# cd test8000
[root@localhost test8000]# ls -l *.csv
-rw-r--r--. 1 root root 432416 3월 14 11:23 moga.csv
-rw-r--r--. 1 root root 432416 3월 14 11:23 moga2.csv
test8000디렉토리의 소유자는 oracle로 변경되었지만 그 밑에 있던 파일들의 소유자는 여전히 root인 것을 확인할 수 있음. 그래서 디렉토리의 소유자를 변경할 때 그 안의 파일들의 소유자도 한번에 oracle로 변경하고 싶다면 -R 옵션을 사용하면 됨.
문제116. /root 밑에 있는 test8000 디렉토리의 소유자를 oracle로 변경할 때 test8000 밑에 있는 파일들의 소유자도 한번에 oracle로 변경되게 하시오.
[root@localhost test8000]# cd
[root@localhost ~]# chown -R oracle:oracle test8000
[root@localhost ~]# cd test8000
[root@localhost test8000]# ls -l *.csv
-rw-r--r--. 1 oracle oracle 432416 3월 14 11:23 moga.csv
-rw-r--r--. 1 oracle oracle 432416 3월 14 11:23 moga2.csv
25 chattr 명령어
chattr명령어를 이용하면 chmod 명령어 수행을 막을 수 있음.
chattr명령어는 최상위 계정인 root에서만 수행할 수 있음.
oracle과 같은 일반 유저가 특정 파일에 대해서 chmod 명령어를 수행하지 못하도록 막는 명령어
[root@localhost test8000]# cd /home/oracle
[root@localhost oracle]# ls
emp.txt
[root@localhost oracle]# ls -l emp.txt
-rwxrwx---. 1 oracle oracle 1036 3월 10 11:29 emp.txt
oracle 계정으로 스위치함.
[root@localhost oracle]# su - oracle
마지막 로그인: 금 3월 11 16:25:27 KST 2022 일시 pts/0
[oracle@localhost ~]$
[oracle@localhost ~]$ ls -l emp.txt
-rwxrwx---. 1 oracle oracle 1036 3월 10 11:29 emp.txt
문제117. 현재 oracle유저에서 emp.txt의 권한을 소유자, 그룹, 기타유저 모두 읽기 권한으로 변경하시오.
[oracle@localhost ~]$ chmod 444 emp.txt
[oracle@localhost ~]$ ls -l emp.txt
-r--r--r--. 1 oracle oracle 1036 3월 10 11:29 emp.txt
emp.txt의 소유자가 oracle이므로 자기 자신의 것이므로 마음대로 emp.txt의 권한을 조정할 수 있음. 그런데 자기 것이지만 권한을 마음대로 조정할 수 없도록 설정할 수 있음.
[oracle@localhost ~]$ su -
암호:
마지막 로그인: 월 3월 14 09:48:26 KST 2022 gateway에서 시작 일시 pts/0
[root@localhost ~]# cd /home/oracle
[root@localhost oracle]# chattr +i emp.txt
[root@localhost oracle]# lsattr emp.txt
----i----------- emp.txt
root 유저로 접소해서 chattr 명령어로 위와 같이 emp.txt를 설정하면 oracle유저는 emp.txt의 소유자이지만 권한 조정을 할 수 없는 상태가 됨.
[root@localhost oracle]# su - oracle
마지막 로그인: 월 3월 14 11:51:00 KST 2022 일시 pts/0
[oracle@localhost ~]$ cd
[oracle@localhost ~]$ ls
emp.txt
[oracle@localhost ~]$ ls -l emp.txt
-r--r--r--. 1 oracle oracle 1036 3월 10 11:29 emp.txt
[oracle@localhost ~]$ chmod 777 emp.txt
chmod: changing permissions of `emp.txt': 명령을 허용하지 않음
[oracle@localhost ~]$ ls -l emp.txt
-r--r--r--. 1 oracle oracle 1036 3월 10 11:29 emp.txt
그럼 다시 oracle유저가 emp.txt에 대해서 chmod명령어로 권한조정을 마음대로 할 수 있도록 되게 하시오.
[oracle@localhost ~]$ su -
암호:
마지막 로그인: 월 3월 14 11:56:00 KST 2022 일시 pts/0
[root@localhost ~]# cd /home/oracle
[root@localhost oracle]# ls
emp.txt
[root@localhost oracle]# chattr -i emp.txt
[root@localhost oracle]# lsattr emp.txt
---------------- emp.txt
[root@localhost oracle]# su - oracle
마지막 로그인: 월 3월 14 11:59:31 KST 2022 일시 pts/0
[oracle@localhost ~]$ chmod 777 emp.txt
[oracle@localhost ~]$ ls -l emp.txt
-rwxrwxrwx. 1 oracle oracle 1036 3월 10 11:29 emp.txt
'Study > class note' 카테고리의 다른 글
리눅스 / maria db (0) | 2022.03.14 |
---|---|
리눅스 / 리눅스 vi편집기 명령어1 (0) | 2022.03.14 |
리눅스 / putty로 서버 접속, 리눅스 명령어2 (0) | 2022.03.11 |
리눅스 / 리눅스 명령어 (0) | 2022.03.10 |
리눅스 설치 (1) | 2022.03.08 |