How the problem happens
You open a file, and while you edit your own copy something else writes the original: another administrator, a configuration management run, a package upgrade or the application itself. If you then save, the other change disappears without an error. Editing locally and uploading over SFTP is especially exposed, because the time between reading and writing is long and a plain upload does not compare anything.
Record the state before you start
Note the checksum and the time of the last change when you download the file. Check them again immediately before uploading. A different checksum means the file changed and you should not overwrite it without looking.
sha256sum /etc/example.conf
stat -c '%y %U %G %a' /etc/example.confCompare and merge the changes
Keep your edited copy under a new name, fetch the current version and compare it with the version you started from and with your own. Then apply your change to the current version instead of overwriting it. The diff3 command can show all three versions together.
diff -u example.conf.orig example.conf.current
diff -u example.conf.orig example.conf.mine
diff3 example.conf.mine example.conf.orig example.conf.currentFind out what is changing the file
If the file keeps changing, find the source before you edit again. Check who has it open and look at the journal and at package history. If configuration management owns the file, change the template there, otherwise the next run will replace your edit.
sudo lsof /etc/example.conf
sudo journalctl --since "1 hour ago" --no-pager | grep example.conf
grep example.conf /var/log/dpkg.logA warning is not a lock
Editors such as vim and nano warn you when a file changed since it was opened, but they do not stop another process from writing it. The same is true of checksum comparisons: a check just before saving makes the window very short, but not zero. On servers where several people work, a version-controlled source of configuration protects you better than any editor.
Save protection in CH-J Server Manager
The File Manager editor checks the file again when saving. If its content, permissions or link target changed, saving stops and the original stays as it is. You can then load the current version from the server, which discards your unsaved changes, so copy your text aside first. The editor does not merge versions for you. For transfers, the app asks before replacing a target that changed or already exists, and tells you to start again if the source changed during the transfer.