[νμΌ μ 보μ κΆν] νμΌμ μ κ·Ό κΆν λ° λ³κ²½ with λ§ν¬
<μμμ§ λμ μ¬λ¬ΌμΈν°λ·μ μν 리λ μ€ νλ‘κ·Έλλ° with λΌμ¦λ² 리νμ΄ μμ μ μ°Έκ³ ν΄μ μμ±νμμ΅λλ€ :-)>
β νλ λ§ν¬μ μ¬λ³Όλ¦ λ§ν¬
λ§ν¬ : ν΄λΉ νμΌμ λ€λ₯Έ κ²μΌλ‘ μ°κ²°ν΄μ μ¬μ©νλ κ°λ
νλ λ§ν¬ : κ°νκ² μ°κ²°λμ΄ μλ κ², νλμ νμΌμ΄ λ κ°μ μ΄λ¦μΌλ‘ λΆλ¦°λ€κ³ μκ°νλ©΄ μ΄ν΄κ° μ½λ€
μ΄λ€ μ΄λ¦μΌλ‘ νμΌμ μμ νλ μλ³Έ νμΌμ μ κ·Ό λ° μμ μ΄ κ°λ₯νλ€
μ¬λ³Όλ§ λ§ν¬ : μ½νκ² μ°κ²°λμ΄ μλ κ², νμΌμ λν κ°μ μ μΈ ν¬μΈν°λ‘ μ€μ νμΌμ λν κ²½λ‘λ₯Ό μ μ₯νλ€
μλμ°μ λ°λ‘κ°κΈ°μ λΉμ·ν κ°λ μλ‘ μλ³Έ νμΌκ³Ό λ§ν¬ νμΌμ΄ λ°λ‘ μ‘΄μ¬νλ―λ‘ κ°κ° μ°Έκ³ ν μ μλ€
νλ λ§ν¬
: νμΌμ λν΄ κ°μ μμ΄λ
Έλλ₯Ό κ°μ§λ€
μ΄λ€ νμΌλ‘ μ κ·Όνλ λμΌν νμΌλ‘ κ°μ£Όλκ³ , κ°μ μμ΄λ
Έλ λΈλ‘μμλ§ μ¬μ©ν μ μκΈ° λλ¬Έμ λ¨μΌ νμΌ μμ€ν
μμλ§ μ¬μ©μ΄ κ°λ₯νλ€
μ¬λ³Όλ¦ λ§ν¬
: μλ³Έ νμΌ μμΉμ λν μμΉ(μμ΄λ
Έλ)λ§μ μ μ₯νκ³ μκΈ° λλ¬Έμ μμ΄λ
Έλμ λ°μ΄ν°κ° λ°λ‘ μ‘΄μ¬νλ€
βοΈ ln λͺ λ Ήμ΄λ νλ λ§ν¬μ μ¬λ³Όλ¦ λ§ν¬ λͺ¨λ μ§μν¨
ln [-s] μλ³Έ_νμΌλͺ
λ§ν¬λλ_μ΄λ¦
μ¬λ³Όλ¦ λ§ν¬λ νμΌμ ls -l λ‘ νμΈν΄λ³΄λ©΄ μλ³Έ νμΌμ κ°λ¦¬ν€κ³ μλ€
νλ λ§ν¬λ νμΌμ 1.txt νμΌμ΄λ 2.txt νμΌ λͺ¨λ κ°μ μμ΄λ Έλλ₯Ό κ°λ¦¬ν€κ³ , λ§ν¬ μκ° μ¦κ°νμμΌλ―λ‘ λ§ν¬ μκ° 2 κ°λ¦¬ν¨λ€
echo λͺ λ Ήμ΄ μ¬μ©νμ¬ 2.txt νμΌμ λ΄μ©μ μΆκ°νλ©΄ 1.txt νμΌμ ν¬κΈ°μ λ΄μ©μ΄ λμΌν΄μ§μ νμΈν μ μλ€
touch 1.txt
ln 1.txt 2.txt
ln -s 1.txt 3.txt
ls -il [1-3].txt
echo "123" >> 2.txt
more 1.txt
ls -il [1-3].txt
β νμΌμ μ κ·Ό κΆν λ³κ²½
βοΈ chmod
chmod λͺ λ Ήμ΄μ μΈμμ νμΌμ μ κ·Ό κΆνμ μ€μ νλλ°, νμΌ μ κ·Ό κΆνμ μ€μ νλ λ°©λ²μ λ¬Έμμ΄μ μ΄μ©νλ λ°©λ²κ³Ό 8μ§μ μ΄μ©νκΈ°
λ¬Έμμ΄μ μ΄μ©ν κΆνμ€μ
u(user/owner) : μμ μ, g(group) : κ·Έλ£Ή, o(others) : λ€λ₯Έ μ¬λ, a(all) : λͺ¨λ μ¬λ
+ : κΆν μΆκ°, - : κΆν μμ
r(read) : μ½κΈ°, w(write) : μ°κΈ°, x(execute) : μ€ν, s(set-user-ID/set-group-ID)
chmod λ³κ²½ν _μ¬μ©μλ©΄ νμΌλͺ
chgrp λ³κ²½ν _κ·Έλ£Ήλͺ
νμΌλͺ
ls -l 2.txt
sudo chmod ug+x 2.txt
ls -l 2.txt
βοΈ νμΌ μ 보 μΆλ ₯ stat
리λ μ€μμ νμΌ μ λν μ 보λ₯Ό μκ³ μΆμ κ²½μ°
νμ¬ νμΌμ μ΄λ¦, ν¬κΈ°, μ¬μ©νλ λΈλ‘μ μ, μμ΄λ Έλμ λν μ 보 λ± λ€μν μ 보λ₯Ό μΆλ ₯ν
stat {νμΌλͺ
}+
β νμ¬ νμΌμ κΆνμ λ³κ²½νκΈ°
// νμ¬ νμΌμ κΆνμ λ³κ²½νλ μ½λ
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
int main(int argc, char **argv) {
struct stat statbuf;
if (argc < 3) {
fprintf(stderr, "Usage: %s file1 file2\n", argv[0]);
return -1;
}
// 1) νμΌμ μ‘΄μ¬ μ¬λΆμ λν μ 보λ₯Ό κ°μ Έμ¨λ€
if (stat(argv[1], &statbuf) < 0) {
perror("stat");
return -1;
}
// 2) chmod ν¨μλ₯Ό νΈμΆν΄μ νμΌμ set-grout-ID λ₯Ό μ€μ νκ³ κ·Έλ£Ήμ μ€ν κΆνμ ν΄μ νλ€
if (chmod(argv[1], (statbuf.st_mode & ~S_IXGRP) | S_ISGID) < 0) {
perror("chmod");
return -1;
}
// 3) 8μ§μ μ΄μ©ν΄μ νμΌμ κΆνμ 644("rw-r--r--") μ λκ°μΌλ‘ μ€μ νλ€
if (chmod(argv[2], S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0) {
perror("chmod");
return -1;
}
// => λΉλν΄μ μ€ννκΈ° μ 4.txt μ€ν κΆνμ μ£Όκ³ μ€ννκΈ°
return 0;
}
/*
gani@gani:~/raspi/File $ umask 0022
gani@gani:~/raspi/File $ gcc -o chmod chmod.c
gani@gani:~/raspi/File $ chmod g+x 4.txt
gani@gani:~/raspi/File $ ls -l 4.txt 5.txt
-rw-r-xr-- 1 gani gani 0 1μ 5μΌ 23:53 4.txt
--w-r--rw- 1 gani gani 0 1μ 5μΌ 23:54 5.txt
gani@gani:~/raspi/File $ ./chmod 4.txt 5.txt
gani@gani:~/raspi/File $ ls -l 4.txt 5.txt
-rw-r-Sr-- 1 gani gani 0 1μ 5μΌ 23:53 4.txt
-rw-r--r-- 1 gani gani 0 1μ 5μΌ 23:54 5.txt
첫 λ²μ§Έ νμΌμ κ·Έλ£Ήμ set-grout-ID κ° μ€μ λκ³ μ€ν κΆνμ΄ μ κ±°λ¨
λ λ²μ§Έ νμΌμ 644 κΆνμΌλ‘ μ€μ λμ΄ μμ
*/
umask 0022
gcc -o chmod chmod.c
chmod g+x 4.txt
ls -l 4.txt 5.txt
./chmod 4.txt 5.txt
ls -l 4.txt 5.txt