Backport configuring history file permissions

This seems to work. Let me know what you think.