Securily changing ownership of a file chown() operates on a file name, and can be vulnerable to a race condition. Instead open() the file in read only mode fstat() the open file descriptor lstat() the file name This may be overkill, depending on the situation Make sure both stat calls point to the file you expect Make sure this is the file you wanted (check uid/etc if needed) fchown() the file descriptor.