Fixing Crontab editor permissions for www-data
Published on 3rd September 2025 Estimated Reading Time: 2 minutesThere are times when I set jobs to run using the web server account www-data
for various website maintenance tasks. To ensure that I am doing this for the right account, I issue the following command:
sudo -u www-data crontab -e
However, doing so on this server yielded the following:
touch: cannot touch '/var/www/.selected_editor': Permission denied
Unable to create directory
/var/www/.local/share/nano/: No such file or directory
It is required for saving/loading search history or cursor positions.
No modification made
While things otherwise worked as they should with nano
as the editor, I felt it best to avoid such output if I could. Thus, I modified the command like this:
sudo -u www-data HOME=/tmp crontab -e
This sets the home directory for www-data
as /tmp
to allow the setting of an editor, at least on an ephemeral basis. The root cause of the messages is that www-data
is not a user account like others and does not get a home area. Thus, the above workaround gets around that, without the artificiality of creating a www-data
folder in the /home directory. Some might get around the whole business using the Vi editor, but nano
suits me better.