Arthur
Arthur

Reputation: 3473

Strange situation with linux permissions

I have some file and can't delete it.

File created my user www-data:

-rw-rw-r-- 1 www-data www-data 17408 Jun  3 16:18 0.48257900 1464959885_555.png

I am trying to delete it by user lifesim:

 rm -rf *
rm: cannot remove '0.48257900 1464959885_555.png': Permission denied

Why I can't delete that file?

lifesim@srvJH:~/public_html/upload/blog/posts/2016-06-03$ whoami
lifesim
lifesim@srvJH:~/public_html/upload/blog/posts/2016-06-03$ id lifesim
uid=1001(lifesim) gid=33(www-data) groups=33(www-data)
lifesim@srvJH:~/public_html/upload/blog/posts/2016-06-03$ id www-data
uid=33(www-data) gid=33(www-data) groups=33(www-data),1001(lifesim)

File created by my PHP script.

Upvotes: 1

Views: 40

Answers (2)

Lars Fischer
Lars Fischer

Reputation: 10149

As clarified in the comments below the question: your lifesim user has no rights to change the directory containing the file.

Give lifsim or the group "w" permissions on the diretory or use the www-data user for the deletion.

Deleting (or creating) a file means we modify the directory (imagine the directory is just a database document with the file metadata) and remove (or add) the metadata of the file. Thus we must be able to change the directory.

Upvotes: 0

daf
daf

Reputation: 1329

Lars Fischer is right: you need to have write permission to delete a file from a directory.

Upvotes: 1

Related Questions