A user with write permission on a directory can delete any file within that directory, unless the directory has the "sticky" bit set (as is commonly set on /tmp
).
In addition, the owner of a directory can delete any file within that directory, regardless of sticky bit or other permissions.
The "sticky" bit when set on a directory is sometimes referred to as the "restricted deletion flag".
If you'd like to prevent your user from being able to delete those files, set the parent directory's sticky bit:
chmod +t some-directory-name
After that, you'll also need to change ownership on the directory (you'll need to do this as root):
sudo chown root some-directory-name
You'll want to ensure that your user can still write to that directory, if losing ownership left your user without write access, you can either grant write access to "other":
sudo chmod o+rwx some-directory-name
Or you can ensure your group has access:
sudo chgrp yourgroup some-directory-name
sudo chmod g+rwx some-directory-name
(Group ownership is not enough to give you the ability to delete the root-owned files.)
Good luck in your adventures, whatever they may be.