Adding a user on .htpasswd

2019-03-08 16:51发布

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?

2条回答
戒情不戒烟
2楼-- · 2019-03-08 17:40

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

查看更多
男人必须洒脱
3楼-- · 2019-03-08 17:49

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

查看更多
登录 后发表回答