Commands/Linux

유저 / 그룹 / 화일 관리

꼰대코더 2025. 2. 28. 17:30

유저 추가

$ sudo adduser user2

/home/user2 폴더생성

config 화일들의 /home/user2 에 복사

패스워드 입력 요구

 

현 유저에서 화일 생성

$ touch newfile
$ ls -al newfile
  -rw-r--r--      1  user1      user1             0 Sep 20 19:25  newfile

rw- : 소유자는 읽기 쓰기만 가능

r--  :  소유자가 속한 그룹의 멤버들은 읽기만 가능

r--  :  타인들은 읽기만 가능

 

퍼미션 변경

$ chmod 760 newfile
$ ls -al newfile
  -rwxrw----      1  user1      user1             0 Sep 20 19:25  newfile

760 의 의미는 아래 참조

혹은 u (소유자) g (그룹) o (others) 에 r, w, x (읽기 쓰기 실행)을 + - 로 가미할 수 도 있다.

$ chmod u-x newfile
$ ls -al newfile
   -rw-rw----      1  user1      user1             0 Sep 20 19:25  newfile

 

유저 교환후 user1이 생성한 newfile 내용보기

$ su user2
$ cat /home/user1/newfile
   cat: /home/user1/newfile: Permission denied

user2는 newfile 에 있어서 others 의 권한( rw-rw---- ) 이므로 읽기 권한이 없다.

이를 해소하기 위해 group을 만들어 user1과 user2를 멤버로 포함시켜면 읽기 쓰기 ( rw-rw---- ) 권한이 부여된다.

 

그룹 만들고 멤버 추가하기 

$ sudo groupadd app-data-group
$ sudo usermod -aG app-data-group user1 user2

 

 

'Commands > Linux' 카테고리의 다른 글

shell 의 환경화일 (.profile, .bashrc)  (0) 2025.03.03
검색  (0) 2025.03.01
소프트웨어 패키지 관리  (0) 2025.03.01
aws 처럼 ssh 로 password 없이 private key 로 접속하기  (0) 2025.03.01
방화벽 (firewall)  (0) 2025.02.28