Linux – Denying timestamp modification on SFTP server

filesystemslinuxsftp

I have a linux SFTP server which I use to share files with other people.

There is a script that automatically find and delete files uploaded more than 10 days ago:

find . -not -path . -mtime +10 -exec rm -frv {} \;

I've noticed that some SFTP clients preserve last modified date, causing the script to delete the files sooner than expected.

For instance, if Today is 15th of December, and a client upload a file that he modified on his computer on the 1st of December, the file gets deleted immediately, instead of the 25th of December.

So, how can I deny the clients to change last modified attribute after the upload?

Best Answer

The sftp-server (and the compatible internal-sftp) has the -P and -p switches to black/white list certain SFTP requests.

You can use them to disallow setstat and fsetstat requests:

Subsystem sftp internal-sftp -P setstat,fsetstat

Note that this will disallow also permissions (and other attributes) changes.

You can of course do this per-user (or per other criteria) using the Match directive.