Trouble setting up basic user authentication on apache2 web server

Hey guys!

So I decided to set up some basic user authentication on my apache2 server, and I am running into some problems. I followed the documentation provided by apache on their website, but I cant create the password file for some reason. I did a little trouble shooting myself, and found out that I need to use htpasswd2.1 as opposed to htpasswd(which is nowhere to be found).

The specific part I am stuck with, is running this command:

htpasswd2.1 -c /opt/apache2/passwords user1

It's displaying htpasswd2.1: command not found.

I am completely stuck, and seeking assistance. Thanks in advance for taking the time to review this.

First, file ./htpasswd2.1 to make sure its what you think it is.

I'm surprised your distribution didn't come with htpasswd though. It might be a slightly different name -- htpasswd instead of htpasswd2.1 -- or not in your PATH. Try whereis htpasswd

1 Like

Hey Corona, thanks alot for your help.

So I ran that command , and got the following:

./htpasswd2.1: troff or preprocessor input text

As for the htpasswd, I read a couple other forums and someone said if you are using apache2, it should be htpasswd2. The only thing with that is, I have a htpasswd2.1 and no htpasswd to be found.

I ran that command as you suggested, and nothing is coming up

whereis htpasswd
htpasswd:

As I suspected, the file you have is not a program -- it is a manual page.

What is your distribution? That would help explain where htpasswd is hiding, or what you need to install to have it. (You really shouldn't go around running random files you downloaded from the internet.)

That advice may be a little old. On my system, htpasswd and htpasswd2 are the same program.

$ ls -l /usr/sbin/htpasswd*
-rwxr-xr-x 1 root root 18688 May 23  2014 /usr/sbin/htpasswd
lrwxrwxrwx 1 root root    18 May 23  2014 /usr/sbin/htpasswd2 -> /usr/sbin/htpasswd

$

Im running openSUSE linux.

Is it hiding in /usr/sbin? ls -l /usr/sbin/htpass*

Doesnt look like it.

ls -l /usr/sbin/htpass*
ls: cannot access /usr/sbin/htpass*: No such file or directory

ls -l /usr/local/apache2/bin/htpass* ? Also check in /sbin.

Nope, same thing displaying. Im convinced its not here haha

If you have apache, it must be somewhere. Time for a brute force search:

find / -name 'htpass*' 2>/dev/null
1 Like

/opt/apache2/htpasswd2.1
/opt/htpasswd2.1.gz
/usr/share/doc/packages/apache2/SHA1/htpasswd-sha1.pl
/usr/share/man/man1/htpasswd2.1.gz

Also, what does the last bit of that script mean? The

 2>/dev/null

It means 'don't print error messages'.

I don't suppose htpasswd needs root to be found on this system...

1 Like

Unfortunately, I ran all these commands as root :eek:

Usually a very bad habit but saves us some time now.

I have no idea why this is missing. It's supposed to come with apache.

Yeah, I tried to find it myself and coudlnt. Even tried uninstall and install, and still cant find it

Try installing "apache2-utils" for SuSe.

zypper install apache2-utils

Refreshing service 'spacewalk'.
Loading repository data...
Reading installed packages...
'apache2-utils' is already installed.
No update candidate for 'apache2-utils-2.2.12-1.50.1.x86_64'. The highest available version is already installed.
Resolving package dependencies...

Nothing to do.

You can try the version that comes with 'thttpd'. One is supposed to come with apache but obviously doesn't.

Can you elaborate?

Installing thttpd -- an alternative http server -- apparently installs its own htpasswd with it in SuSe. You don't have to use its daemon, just install it to get that tool.