setgid 가 설정되어 있는 디렉토리에 파일을 생성하면, 당연히 664 로 권한 설정이 된다.
$ touch abcd $ ll drwxr-sr-x 1 usera nfs 28 2020-10-04 20:36 . drwxrwsr-x 1 usera nfs 218 2020-10-04 17:55 .. -rw-rw-r-- 1 usera nfs 0 2020-10-04 20:36 abcd
그런데.. 여기에 파일을 복사(rsync, cp) 해온다면? 원 파일에 group write 권한이 있을 경우는 그 권한이 그대로 유지되고, 소유권은 현재 디렉토리에 따라 바뀌게 된다.
그룹 쓰기 권한이 없을 경우? 당연히 그 권한 그대로 유지된다.
$ ll -rw-rw-r-- 1 usera nfs 32K 2020-10-04 18:27 repository_backup.log -rw-r--r-- 1 usera nfs 11K 2020-10-04 20:39 shutdown-test.log
두 파일 아무 선택사항 없이 rsync 로 복사했다. 모두 그룹은 nfs 로 바뀌었는데, 그룹 권한은 원 파일 그대로 유지됐다.
현 디렉토리(Destination)의 Umask 는 002 이고, setgid 가 설정되어 있어서, 그룹 쓰기가 설정되어 있어야만 의미가 있는데..
왜 touch 를 하면 umask 를 따라가는데, 복사를 하면 안되는 걸까?
‘왜’는 모르겠고, 되게끔 하는 방법은 찾을 수 있었다. 추석 연휴의 마지막 날, 1시간이면 끝낼 수 있으리란 작업이 무려 6시간쯤 걸렸다.
cp 로 하는 방법은 모르겠고, rsync 를 사용, 다음과 같이 ‘긴~’ 선택사항을 넣어주면 된다.
rsync --no-p --no-g --chmod=ugo=rwX src/ dest/
이러면, 복사된 파일은 그 파일이 위치한 디렉토리의 권한을 그대로 따라간다.
chmod 가 중요한데, ugo=rwX 로 해야 non-masked bits 가 사용가능하게 된다고 한다. (그런데, masked bit 이 뭔지 모르겠네.)
늘 그렇지만, 파랑새는 가까운 곳에, man page 에 있었다.
그런데, 읽어봐도 무슨 뜻인지는 정확하게 이해할 수가 없다.
In summary: to give destination files (both old and new) the source permissions, use –perms. To give new files the destination-default permissions (while leaving existing files unchanged), make sure that the –perms option is off and use –chmod=ugo=rwX (which ensures that all non-masked bits get enabled).
If you’d care to make this latter behavior easier to type, you could define a popt alias for it, such as putting this line in the file ~/.popt (the following defines the -Z option, and includes –no-g to use the default group of the destination dir)
man rsync
popt alias 는 지금까지 리눅스 생활 몇십년만에 처음 들어보는데.. 찾아봐도 잘 나오질 않는다. 굳이 alias 까지 필요하진 않으니 그냥 저렇게 길게 쓰면 되겠지.