歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> htpasswd命令用法詳解

htpasswd命令用法詳解

日期:2017/2/27 15:58:55   编辑:Linux教程
Linux/1727.html' target='_blank'>htpasswd建立和更新存儲用戶名、密碼的文本文件, 用於對HTTP用戶的basic認證。

# /usr/local/apache/bin/htpasswd --help
Usage:
htpasswd [-cmdpsD] passwordfile username
htpasswd -b[cmdpsD] passwordfile username password

htpasswd -n[mdps] username
htpasswd -nb[mdps] username password
-c Create a new file.
-n Don't update file; display results on stdout.
-m Force MD5 encryption of the password (default).
-d Force CRYPT encryption of the password.
-p Do not encrypt the password (plaintext).
-s Force SHA encryption of the password.
-b Use the password from the command line rather than prompting for it.
-D Delete the specified user.
On other systems than Windows, NetWare and TPF the '-p' flag will probably not work.
The SHA algorithm does not use a salt and is less secure than the MD5 algorithm.

htpasswd參數
-c 創建passwdfile.如果passwdfile 已經存在,那麼它會重新寫入並刪去原有內容.
-n 不更新passwordfile,直接顯示密碼
-m 使用MD5加密(默認)
-d 使用CRYPT加密(默認)
-p 使用普通文本格式的密碼
-s 使用SHA加密
-b 命令行中一並輸入用戶名和密碼而不是根據提示輸入密碼,可以看見明文,不需要交互
-D 刪除指定的用戶

實例
1. 如何利用htpasswd命令添加用戶?
# /usr/local/apache/bin/htpasswd -bc linuxeye_pd linuxeye_user linuxeye_password
Adding password for user linuxeye_user
# cat linuxeye_pd
linuxeye_user:$apr1$Mugpp3FE$zGsi7/JfQIhFXPlgqo/Wx/
生成當前目錄下生成一個linuxeye_pd文件,用戶名linuxeye_user,密碼:linuxeye_password,默認采用MD5加密方式

2. 如何在原有密碼文件中增加下一個用戶?
# /usr/local/apache/bin/htpasswd -b linuxeye_pd linuxeye.com linuxeye.com
Adding password for user linuxeye.com
# cat linuxeye_pd
linuxeye_user:$apr1$Mugpp3FE$zGsi7/JfQIhFXPlgqo/Wx/
linuxeye.com:$apr1$/8EUOPYI$4MBxYpzotrSDcTTDZvTeT0
一定要去掉-c選項,否則覆蓋密碼文件再創建

3. 如何不更新密碼文件,只顯示加密後的用戶名和密碼?
# /usr/local/apache/bin/htpasswd -n linuxeye
New password:
Re-type new password:
linuxeye:$apr1$bZ6Gclc4$zKRap.0BADzZIxLoxpDNv0

# /usr/local/apache/bin/htpasswd -nb linuxeye linuxeye_password
linuxeye:$apr1$yvngdKGV$QrnlriJ.MxIu52Vmo.ROE1

4. 如何利用htpasswd命令刪除用戶名和密碼?
# /usr/local/apache/bin/htpasswd -D linuxeye_pd linuxeye_user
Deleting password for user linuxeye_user
# cat linuxeye_pd
linuxeye.com:$apr1$/8EUOPYI$4MBxYpzotrSDcTTDZvTeT0

5. 如何利用htpasswd命令修改密碼?
# /usr/local/apache/bin/htpasswd -D linuxeye_pd linuxeye.com
Deleting password for user linuxeye.com
# /usr/local/apache/bin/htpasswd -b linuxeye_pd linuxeye.com linuxeye_passwd
Adding password for user linuxeye.com
# cat linuxeye_pd
linuxeye.com:$apr1$74ZvB1vC$/b7ETmg8xhDPieYj0b0cE.
需要先利用htpasswd命令刪除指定用戶,再利用htpasswd添加用戶命令創建用戶即可實現修改密碼的功能。
Copyright © Linux教程網 All Rights Reserved