pxkw.hatenadiary.com

めもめも

symlinkをchownする

オプションhを付与する。

chown -h owner:group symlink

chownのマニュアル:

  -h, --no-dereference   affect each symbolic link instead of any referenced
                         file (useful only on systems that can change the
                         ownership of a symlink)

なので、 -h を付与しないと参照先の所有権を変えてしまう。


symlinkでのみアクセスできるみたいなことできるのかな

--> できない。

$ ls -l
    (略)
-r--------  1 root root   16 Jan 28 16:33 testfile
lrwxrwxrwx  1 pxkw pxkw    8 Jan 28 16:31 testlink -> testfile
    (略)
$ sudo cat testfile 
can you see me?
$ cat testfile 
cat: testfile: Permission denied
$ cat testlink 
cat: testlink: Permission denied

symlinkは読み書き権限の変更不可

chmodのマニュアル:

       chmod never changes the permissions of symbolic links; the chmod system call cannot change their permissions.  This is not a  problem  since
       the permissions of symbolic links are never used.  However, for each symbolic link listed on the command line, chmod changes the permissions
       of the pointed-to file.  In contrast, chmod ignores symbolic links encountered during recursive directory traversals.

hardlinkの権限/所有者変更はすべてのhardlinkに影響する

$ ls -l
    (略)
-rw-rw-r--  3 pxkw pxkw    0 Jan 28 16:40 file
-rw-rw-r--  3 pxkw pxkw    0 Jan 28 16:40 ln1
-rw-rw-r--  3 pxkw pxkw    0 Jan 28 16:40 ln2
    (略)
$ chmod 777 ln1
$ ls -l
    (略)
-rwxrwxrwx  3 pxkw pxkw    0 Jan 28 16:40 file*
-rwxrwxrwx  3 pxkw pxkw    0 Jan 28 16:40 ln1*
-rwxrwxrwx  3 pxkw pxkw    0 Jan 28 16:40 ln2*
    (略)
$ sudo chown root:root ln2
$ ls -l
    (略)
-rwxrwxrwx  3 root root    0 Jan 28 16:40 file*
-rwxrwxrwx  3 root root    0 Jan 28 16:40 ln1*
-rwxrwxrwx  3 root root    0 Jan 28 16:40 ln2*
    (略)