My question is simple.
How to allow users to change their passwords stored in some htpasswd file in linux without revealing the files content or allow users to modify other passwords?
I tried to write a script to do that job using ssh and specialy-designed user but it leads noway.
Please help.
I am using Debian server “Lenny”.
The Apache
htpasswdfile does not support any shadow functionality. Therefor you have to prevent the users accessing your web server in order to keep them away from the password file. So the only solution is your SSH based approach or any other remote solution. The following description will explain how to write a SSH command script to change the password only if the user knows his old password. The major problem is, that Apache does not provide a command line tool to verify a password in ahtpasswdfile. But this can be done by hand.The following description assumes that the web server user is
www-dataand that the home directory of the user is/var/www.First you have to create a htpasswd file, that is writable by the web server user:
Then you have to add the keys of all your users to the
authorized_keysfile of the web server user. You have to prefix each line with thecommandoption.Whenever a user connects with his key only the
.htpasswd.shgets executed. The users do not have any shell access to the web server.This is the script to change the password:
The tricky part is the password verification. It is done by reading the old salt and encrypting the old password with the old salt. The result is compared with the old encrypted password in the
htpasswdfile.Now the user can connect to the web server in order to change the password:
Everybody can change only his own password and nobody has access to the encrypted passwords of the other users. This solution has an additional benefit about using the original
htpasswdprogram in a shell script, because the passwords are never used as a command line argument. This would not be possible withhtpasswd, because it can not read the password from stdin likemkpasswd.