Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4614658
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:43:52+00:00 2026-05-22T01:43:52+00:00

My question is simple. How to allow users to change their passwords stored in

  • 0

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”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:43:52+00:00Added an answer on May 22, 2026 at 1:43 am

    The Apache htpasswd file 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 a htpasswd file. But this can be done by hand.

    The following description assumes that the web server user is www-data and 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:

    # ls -la .htpasswd
    -rw-r--r-- 1 www-data root 18 10. Mai 16:30 .htpasswd
    

    Then you have to add the keys of all your users to the authorized_keys file of the web server user. You have to prefix each line with the command option.

    # cat .ssh/authorized_keys 
    command="/var/www/.htpasswd.sh" ssh-rsa AAAA... user@host
    

    Whenever a user connects with his key only the .htpasswd.sh gets executed. The users do not have any shell access to the web server.

    This is the script to change the password:

    #! /bin/bash
    
    HTPASSWD=/var/www/.htpasswd
    
    die () { echo "$*" >&2 ; exit 1 ; }
    
    read -p 'Enter user name: ' USER
    read -s -p 'Old password: ' OLDPW ; echo
    read -s -p 'New password: ' NEWPW0 ; echo
    read -s -p 'Re-type new password: ' NEWPW1 ; echo
    
    if LINE=$(grep ^"$USER": "$HTPASSWD")
    then
        echo "$LINE" | sed 's/.*:\(..\)\(.\+\)/\1 \2/' | { 
            read SALT CRYPT
            if [[ "$SALT$CRYPT" = $(echo "$OLDPW" | mkpasswd -sS "$SALT") ]] ; then
                if [ "$NEWPW0" != "$NEWPW1" ] ; then
                    die "Password verification error!"
                fi
                PWS=$(grep -v ^"$USER:" "$HTPASSWD")
                {
                    echo "$PWS"
                    echo -n "$USER:"
                    echo "$NEWPW0" | mkpasswd -s
                } > "$HTPASSWD"
                echo "Updating password for user $USER."
            else
                die "Password verification error!"
            fi
        }
    else
        die "Password verification error!"
    fi
    

    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 htpasswd file.

    Now the user can connect to the web server in order to change the password:

    $ ssh www-data@localhost
    Enter user name: szi
    Old password: 
    New password: 
    Re-type new password: 
    Updating password for user szi.
    Connection to localhost closed.
    

    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 htpasswd program in a shell script, because the passwords are never used as a command line argument. This would not be possible with htpasswd, because it can not read the password from stdin like mkpasswd.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a simple question. Is there a way to allow users to enter
Question simple and quick: I have started to use Netbeans to write some code
Pretty simple question. I have a few ASP RequiredFieldValdators checking some text boxes. Out
Question is simple: I have two List List<String> columnsOld = DBUtils.GetColumns(db, TableName); List<String> columnsNew
Simple question here: is there any way to convert from a jagged array to
Ok simple question. I have a JSF application, containing a login page. The problem
Simple question... How am I going to reproduce Javascript bugs if I don't have
Simple question, the answer may not be... I'm going to be developing a web
Simple question - what does this actually do? var oq = (ObjectQuery<TEntity>)L2EQuery; return ExecuteFirstorDefault<TEntity>(oq,
Very simple question, I made the following program : #include <stdlib.h> int main(int argc,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.