I'm getting a permissions error in CentOS 7 when I try to create a hard link. With the same permissions set in CentOS 6 I do not get the error. The issue centers on group permissions. I'm not sure which OS version is right and which is wrong.
Let me illustrate what's happening. In my current working directory, I have two directories: source and destination. At the start, destination is empty; source contains a text file.
[root@tc-dlx-nba cwd]# ls -l total 0 drwxrwxrwx. 2 root root 6 Jun 12 14:33 destination drwxrwxrwx. 2 root root 21 Jun 12 14:33 source [root@tc-dlx-nba cwd]# ls -l destination/ total 0 [root@tc-dlx-nba cwd]# ls -l source/ total 4 -rw-r--r--. 1 root root 8 Jun 12 14:20 test.txt [root@tc-dlx-nba cwd]#
As you can see, regarding the permissions the two directories are 777, with both the owner and group set to root. The text file's owner and group are also both set to root. However, the text file's permissions are read-write for the owner but read-only for the group.
When I'm logged in as root, I have no problem creating a hard-link in the destination directory pointing to the text file (in the source directory).
[root@tc-dlx-nba cwd]# ln source/test.txt destination/ [root@tc-dlx-nba cwd]# ls destination/ test.txt
However, if I log in as another user, in this case, admin, I cannot create the link. I get: "Operation not permitted."
[root@tc-dlx-nba cwd]# rm -f destination/test.txt [root@tc-dlx-nba cwd]# su admin bash-4.2$ pwd /root/cwd bash-4.2$ ln source/test.txt destination/ ln: failed to create hard link ‘destination/test.txt’ => ‘source/test.txt’: Operation not permitted
What happens actually makes sense to me, but since the above is allowed in CentOS 6, I wanted to check to see if I was misunderstanding something. To me, it seems like a bug in CentOS 6 that has been fixed in CentOS 7.
Anyone know what gives? Am I right believing that the above behavior is the correct behavior? Is it CentOS 6 that is correct? Or, are both right and perhaps there is some subtle group permissions issue that I'm missing? Thanks.
Edit: I tried the same test just now on a Debian v7 VM that I have. Debian agrees with CentOS 7: "Operation not permitted."
Edit #2: I just tried the same thing on Mac OS X (Yosemite). That worked the way CentOS 6 did. In other words, it allowed the link to be created. (Note: On OS X, the root group is called "wheel." That's the only difference, as far as I can tell.)