Linux – getting “Permission denied” while trying to create a file

file-permissionslinux

jenkins@hostname:~/dir1/dir2$ ls -ld /some-nfs
drwxrwxrwx 121 171 146 6290 Feb  8 15:38 /some-nfs

jenkins@hostname:~/dir1/dir2$ ls -ld /some-nfs/important-dir
drwxrwxrwx 3 jenkins jenkins 28 Feb  8 15:39 /some-nfs/important-dir

jenkins@hostname:~/dir1/dir2$ mkdir /some-nfs/important-dir/important-dir/logs # able to create a dir

jenkins@hostname:~/dir1/dir2$ ls -ld /some-nfs/important-dir/logs
drwxrwxr-x 2 jenkins jenkins 0 Feb  8 15:39 /some-nfs/important-dir/logs

jenkins@hostname:~/dir1/dir2$ touch /some-nfs/important-dir/logs/file # not able to create a file
touch: cannot touch ‘/some-nfs/important-dir/logs/file’: Permission denied

Why am I getting Permission denied in the last step ?

I was expecting to be able to create the file.

Best Answer

NFS by default will downgrade any files created with the root permissions to the nobody:nogroup user:group.

This is a security feature that prevents privileges from being shared unless specifically requested.

It may be that you would like to enable the "no_root_squash" option in the nfs server's /etc/exports file.

There is a really nice article about root_squash that I recommend you to read before deciding if it's the correct solution for you.