Problem:
You are trying to add/change a password in a htpasswd
file using a command like
htpasswd auth.htpasswd myuser
but you see this error message:
htpasswd: cannot open file htpasswd for read/write access
Solution:
htpasswd
is trying to tell you that it got Permission denied
when accessing the htpasswd file and hence can’t read it or it can’t write the file (auth.htpasswd
in this example).
There are multiple ways to fix this:
- Run
htpasswd
usingsudo
, e.g.sudo htpasswd auth.htpasswd myuser
- Fix the permissions of the file, e.g. using
sudo chown $USER auth.htpasswd chmod o+rw auth.htpasswd
Note that this permanently modifies the permissions for the
htpasswd
file and hence might create additional security risks! - Use a different
htpasswd
file to which you have access. You need to change the configuration on your webserver etc (i.e. the software that is using thehtpasswd
file). This option isn’t always available – e.g. if you can’t change the webserver’s configuration, you just have the option of asking the system administrator nicely.