Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a user on .htpasswd

I am using .htpasswd to password protect certain directory on my server. However, I noticed that everytime I do this sudo htpasswd -c /etc/apache2/.htpasswd newuser my current contents of .htpasswd will be overwritten. Every directory of my site has their own user on .htpasswd.

How can I not overwrite instead add a new user on my .htpasswd?

like image 806
fishcracker Avatar asked Jan 30 '13 02:01

fishcracker


People also ask

How do I remove a user from htpasswd?

To remove a user: Just open the password file using nano or vim and simply remove the user line that you want to delete...

What is a .htpasswd file?

htpasswd file is typically used when protecting a file, folder, or entire website with a password using HTTP authentication and implemented using rules within the . htaccess file. User credentials are stored on separate lines, with each line containing a username and password separated by a colon (:).

How do I use htpasswd command?

htpasswd, use the “-c” option to create the file with the first user. It will prompt you for a password and encrypt it for you. The AuthUserFile location doesn't need to be in the same folder as your virtualhost. It can be anywhere on your server as long as you use the full path to it.


2 Answers

Exact same thing, just omit the -c option. Apache's docs on it here.

htpasswd /etc/apache2/.htpasswd newuser

Also, htpasswd typically isn't run as root. It's typically owned by either the web server, or the owner of the files being served. If you're using root to edit it instead of logging in as one of those users, that's acceptable (I suppose), but you'll want to be careful to make sure you don't accidentally create a file as root (and thus have root own it and no one else be able to edit it).

like image 195
Corbin Avatar answered Sep 19 '22 23:09

Corbin


FWIW, htpasswd -n username will output the result directly to stdout, and avoid touching files altogether.

like image 30
Curtis Mattoon Avatar answered Sep 19 '22 23:09

Curtis Mattoon