Which permissions affect hard link creation? Does file ownership itself matter?
Suppose user alice
wants to create a hard link to the file target.txt
in a directory target-dir
.
- Which permissions does
alice
need on bothtarget.txt
andtarget-dir
? - If
target.txt
is owned by userbill
andtarget-dir
is owned by userchad
, does that change anything?
I've tried to simulate this situation by creating the following folder/file structure on an ext4
filesystem:
#> ls -lh . *
.:
drwxr-xr-x 2 bill bill 60 Oct 1 11:29 source-dir
drwxrwxrwx 2 chad chad 60 Oct 1 11:40 target-dir
source-dir:
-r--r--r-- 1 bill bill 0 Oct 1 11:29 target.txt
target-dir:
-rw-rw-r-- 1 alice alice 0 Oct 1 11:40 dummy
While alice
can create a soft link to target.txt
, she can't create a hard link:
#> ln source-dir/target.txt target-dir/
ln: failed to create hard link ‘target-dir/target.txt’ => ‘source-dir/target.txt’: Operation not permitted
If alice
owns target.txt
and no permissions are changed, the hard link succeeds. What am I missing here?
target.txt
andtarget-dir
permissions, unless Isudo
as root.alice
.I can access both the original file and a hard-link to it (created withsudo
), but I can't create the link as the useralice
despite we all agreeing these permissions should be enough for it.