Skip to content

Just Code

Share Codes I Am Using or Studying




Menu
  • 首页
  • PHP Mysql 网站开发
    • Php / Pear / Mysql / Node.js
    • WordPress / Magento / Shopify
  • Python 编程
  • Java 编程
    • Phone / IOS / Objective-C / Swift
    • JavaSE
    • Java / Jsp
  • Linux Shell 编程
    • Mac / Github / Shell / Linux
    • Tools
  • JS 前端
    • Javascript /Jquery / React / Bootstrap
    • HTML5 / CSS / SVG
    • Google / Facebook / Amazon
  • AI 机器学习
  • Movies 电影电视剧线上看
  • 跨境电商
May 31, 2018
HomePhp / Pear / Mysql / Node.jsphpmyadmin: 通过htaccess和htpasswd设置弹出登录窗口, PhpMyAdmin两步验证, Add an Extra Layer of Security, PhpMyAdmin Login Interface

phpmyadmin: 通过htaccess和htpasswd设置弹出登录窗口, PhpMyAdmin两步验证, Add an Extra Layer of Security, PhpMyAdmin Login Interface

By Gideon Php / Pear / Mysql / Node.js  1 Comment

 

第一步:添加下面的代码到 /etc/apache2/sites-available/000-default.conf 或者 /etc/httpd/conf/httpd.conf

Add these lines to the Apache configuration file (/etc/apache2/sites-available/000-default.conf or /etc/httpd/conf/httpd.conf):

/etc/apache2/sites-available/000-default.conf – On Ubuntu

<Directory /usr/share/phpmyadmin>
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd # or/etc/phpmyadmin/.htpasswd
Require valid-user
</Directory>

/etc/httpd/conf/httpd.conf – On CentOS

<Directory /usr/share/phpmyadmin>
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/httpd/.htpasswd
Require valid-user
</Directory>

 

第二步:使用 htpasswd 命令创建一个用户和密码

Then use htpasswd to generate a password file for an account that will be authorized to access the phpmyadmin login page. We will use /etc/apache2/.htpasswd and ikeepstudying in this case:

#---------- On Ubuntu/Debian Systems ---------- 
sudo htpasswd -c /etc/apache2/.htpasswd  ikeepstudying

#---------- On CentOS/RHEL Systems ---------- 
sudo htpasswd -c /etc/httpd/.htpasswd ikeepstudying

然后他会提示你输入密码,二次输入你的密码即可!Enter password twice and then change the permissions and ownership of the file.

注意:AuthUserFile   需要  apache2-utils  支持,如果没有的话,通过下面的命令安装:

sudo apt-get install apache2-utils

 

第三步:修改 .htpasswd  文件的权限和组,因为Ubuntu 匿名用户是  www-data   CentOS匿名用户是 apache

This is to prevent anyone not in the www-data or apache group from being able to read .htpasswd:

sudo chmod 640 /etc/apache2/.htpasswd

#---------- On Ubuntu/Debian Systems ---------- 
sudo chgrp www-data /etc/apache2/.htpasswd 

#---------- On CentOS/RHEL Systems ---------- 
sudo chgrp apache /etc/httpd/.htpasswd

最后打开网址,检查一下:
Go to http://<ip address>/phpmyadmin and you’ll see the authentication dialog before accessing the login page.

 

注意:没有出现的话,也可以尝试重启apache:

sudo service apache2 restart

 

拓展:htpasswd 用法

htpasswd命令是Apache的Web服务器内置工具,用于创建和更新储存用户名、域和用户基本认证的密码文件。

语法

htpasswd(选项)(参数)

htpasswd [-cmdpsD] passwordfile username
htpasswd -b[cmdpsD] passwordfile username password
htpasswd -n[mdps] username
htpasswd -nb[mdps] username password

选项

–c 创建一个加密文件
–n 不更新加密文件,只将apache htpasswd命令加密后的用户名密码显示在屏幕上
–m 默认apache htpassswd命令采用MD5算法对密码进行加密
–d apache htpassswd命令采用CRYPT算法对密码进行加密
–p apache htpassswd命令不对密码进行进行加密,即明文密码
–s apache htpassswd命令采用SHA算法对密码进行加密
–b 在apache htpassswd命令行中一并输入用户名和密码而不是根据提示输入密码
–D 删除指定的用户

在Windows, NetWare and TPF 系统中-m选项是默认的,在使用apache htpasswd命令时可以忽略。在其他系统中-p选项可能不能工作。

参数

  • 用户:要创建或者更新密码的用户名;
  • 密码:用户的新密码。

实例

1.htpasswd命令添加用户

htpasswd -bc .passwd ikeepstuding pass //当前目录下生成一个.passwd文件,用户名ikeepstuding ,密码:pass,默认采用MD5加密方式

2.在原有密码文件中增加新用户

htpasswd -b .passwd justcode pass //去掉c选项,即可在第一个用户之后添加第二个用户,依此类推

3.不更新密码文件,只显示加密后的用户名和密码

htpasswd -nb ikeepstuding pass  //不更新.passwd文件,只在屏幕上输出用户名和经过加密后的密码

4.删除用户名和密?

htpasswd -D .passwd ikeepstuding

5.利用htpasswd命令修改密码

htpasswd -b .passwd ikeepstuding pass  //直接使用第2种新增用户的方法,ikeepstuding为原有用户,pass为新密码,不需要用下面删除再新建用户!!
# htpasswd -D .passwd ikeepstuding
# htpasswd -b .passwd ikeepstuding pass
#即先使用htpasswd删除命令删除指定用户,再利用htpasswd添加用户命令创建用户即可实现修改密码的功能

 

 

本文:phpmyadmin: 通过htaccess和htpasswd设置弹出登录窗口, Add an Extra Layer of Security, PhpMyAdmin Login Interface

Loading

Related Posts

  • 设置/修改 phpmyadmin 密码 (MAMP) , ERROR 1698 (28000): Access denied for user 'root'@'localhost', Can’t log into phpMyAdmin: mysqli_real_connect(): (HY000/1698): Access denied for user ‘root’@’localhost’

    在使用phpMyAdmin操作数据库时,首先需要设置mysql的root用户的密码。具体操作参考前一篇博文。设置完mysql的root密码之后,需要对phpMyAdmin的登录进行一些配置。 未经配置的phpMyAdmin很不安全,容易受到攻击,或者根本无法正常使用,phpMyAdmin有3种授权模式: cookie: 显示一个web登录页面,输入mysql的用户名和密码,然后进入管理界面 http: 显示1个windows登录框,输入mysql的用户名和密码,然和进入管理 config: 把mysql用户名和密码直接填入config.inc.php,不显示登录界面,直接进入管理界面  …

  • Magento: How to add custom qty field to custom option of simple product magento

    By default in magento there is no qty field…

  • Linux: url打开phpmyadmin, how to access phpmyadmin in lamp
    Linux: url打开phpmyadmin, how to access phpmyadmin in lamp

    问题: I have installed LAMP on ubuntu, and I want to acced PhpMyAdmin,…

Tags:Add an Extra Layer of Security, hpMyAdmin两步验证, htpasswd 用法, PhpMyAdmin Login Interface, phpmyadmin: 通过htaccess和htpasswd设置弹出登录窗口, Secure your phpMyAdmin Instance

Related Posts

3种权限管理方案

PHP错误类型及屏蔽方法

PHP错误类型及屏蔽方法

PHP利用FPDI 制作PDF 档案 (php合并pdf, php签名pdf)

PHP利用FPDI 制作PDF 档案 (php合并pdf, php签名pdf)

About Author

Gideon

One Comment

Add a Comment

Cancel reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

站内搜索

多语言转换

Recent Posts

  • AdobePhotoshopCS6 免安装 精简版
  • 谷歌表格, 谷歌表格公式, 如何计算 Google 表格中两个日期之间的差异, How to Calculate the Difference Between Two Dates in Google Sheets
  • 干货│Amazon Post怎么用?免费的引流利器你还不会?Amazon Post是什么? 如何创建亚马逊POST呢?
  • Xorg模式切换, 解决Shutter失效问题, Ubuntu 22.04 Xorg模式, How to enable/disable wayland on Ubuntu 22.04 Desktop
  • 升级到Ubuntu22之后运行 php7.4 , php7.4 in my Apache in Ubuntu 22, Tutorial Install and Configure PHP on Ubuntu 22.04,tu 22.04 run php7.4

站内搜索




Tags

2021完整版 2022完整版 Chrome插件 css FullCalendar git Google Cloud Platform HTML java javascript javase jquery json linux 自动化 List lunar machine learning magento magneto MySQL php python qq Shell: expect - 自动交互脚本 Shell脚本 shell自动化 Spring Boot Ubuntu WebDriverIO 入门 WebDriverIO 教程 wordpress 买车必读 二手车 人工智能学习 农历 吴京 技术 文咏珊 时间戳 易烊千玺 电影 线上看 网页爬虫 节日 节气




Categories

  • AI 机器学习
  • Apache / VPN / Software
  • Codeigniter / CakePHP
  • Div / Css / XML / HTML5 / SVG
  • Google / Facebook / Amazon / Twitter / Network
  • Java / Jsp
  • Javascript /Jquery / React / Bootstrap / Web
  • JavaSE
  • movies
  • Others
  • Perl / Koha / Ruby / Markdown
  • Phone / IOS / Objective-C / Swift
  • Php / Pear / Mysql / Node.js
  • Python / Wxpython
  • SEO
  • Tools
  • Ubuntu / Mac / Github / Aptana / Nginx / Shell / Linux
  • Videos
  • WP / Joomla! / Magento / Shopify / Drupal / Moodle / Zimbra
  • 二手车
  • 会计
  • 跨境电商




Recent Comments

  • Splinter基本用法, python splinter用法, python自动化, Splinter实例, python网络爬虫, python selenium, python selenium框架 - Just Code on Xpath cheatsheet, XPath用法详解
  • Selenium webdriver 读取认证码, 读取亚马逊Amazon认证码, helium webdriver读取验证码, python读取图形验证码, Solve text captcha, python_anticaptcha - Just Code on helium详细教程, 轻量级Selenium webdriver, Python 自动化, helium安装升级, Helium实现web的自动化, 氦气, Helium文档
  • 簡詩樂見蘇七提到這件事,她先俏皮的朝顧子承做了個鬼臉,而後才認真下來,開口回道。 – Neftetreid on 100 个免费翻墙工具
  • 夜景辰不是已經死了么?他二王兄也親自去認過屍,確定從塞靈河中尋到的屍體就是夜景辰。 – Starving Vendors on 100 个免费翻墙工具
  • WebDriverIO 教程六:在 Selenium 中处理下拉列表, Handling Dropdown In Selenium, WebDriverIO 教程, WebDriverIO 入门 - Just Code on WebDriverIO 教程五:Selenium 定位器实例, Uses Selenium Locators in a Unique Way, WebDriverIO 教程, WebDriverIO 入门







  • 首页
  • PHP Mysql 网站开发
    • Php / Pear / Mysql / Node.js
    • WordPress / Magento / Shopify
  • Python 编程
  • Java 编程
    • Phone / IOS / Objective-C / Swift
    • JavaSE
    • Java / Jsp
  • Linux Shell 编程
    • Mac / Github / Shell / Linux
    • Tools
  • JS 前端
    • Javascript /Jquery / React / Bootstrap
    • HTML5 / CSS / SVG
    • Google / Facebook / Amazon
  • AI 机器学习
  • Movies 电影电视剧线上看
  • 跨境电商




Just Code Copyright © 2025.
Theme by iKeepStudying. Back to Top ↑
Please support this website by adding us to your whitelist in your ad blocker. Ads are what helps us bring you premium content! Thank you!