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 机器学习
  • 線上看電影電視綜藝
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

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to email this to a friend (Opens in new window)
  • Click to print (Opens in new window)
  • More
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

相关

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,不显示登录界面,直接进入管理界面     具体的参数配置如下所示: /* Authentication type…

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

    By default in magento there is no qty field of simple product for custom…

  • 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, and I don't know it's…

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

Related Posts

Mysql常用函数之数值函数

Mysql常用函数之数值函数

PHP保存Base64图片 Convert Base64 string to an image file

PHP保存Base64图片 Convert Base64 string to an image file

PHP编码规范(中文版): PSR-0

About Author

Gideon

One Comment

Leave a Reply Cancel reply

站内搜索

多语言转换

Recent Posts

  • 亲测:IntelliJ IDEA 2020.3.2 破解新招 – 无限重置30天试用期
  • 2020-12-31 亲测有效:JetBrains 2020.3.x 最新激活文件
  • Shopify:如何找到“MailChimp form action URL”?, How To Find The MailChimp Form Action URL?
  • Shopify SEO:Shopify使用Google的站长工具, Shopify使用Google Search Console, 提交Shopify产品链接到Google Search Console
  • 2020-11-30 亲测有效:IntelliJ IDEA 2020.2.3 最新激活破解方法, 激活到 2089 年

站内搜索




Recent Comments

  • 2020-12-31 亲测有效:JetBrains 2020.3.x 最新激活文件 - Just Code on 亲测:IntelliJ IDEA 2020.3.2 破解新招 – 无限重置30天试用期
  • 亲测:IntelliJ IDEA 2020.3.2 破解新招 - 无限重置30天试用期 - Just Code on 2020-11-30 亲测有效:IntelliJ IDEA 2020.2.3 最新激活破解方法, 激活到 2089 年
  • 2020-11-30 亲测有效:IntelliJ IDEA 2020.2.3 最新激活破解方法, 激活到 2089 年 - Just Code on 亲测:IntelliJ IDEA 2020.3.2 破解新招 – 无限重置30天试用期
  • 2020-09-09 亲测有效:IntelliJ IDEA 2020.2 最新全家桶系列产品激活破解方法, JetBrains 全家桶激活 - Just Code on 2020-11-30 亲测有效:IntelliJ IDEA 2020.2.3 最新激活破解方法, 激活到 2089 年
  • 2020-10-28 亲测有效:IntelliJ IDEA 2020.2.3 最新激活破解方法, 激活到 2089 年 - Just Code on 亲测:IntelliJ IDEA 2020.3.2 破解新招 – 无限重置30天试用期




Categories

  • AI 机器学习
  • Codeigniter / CakePHP
  • Div / Css / XML / HTML5 / SVG
  • Google / Facebook / Amazon / Twitter / Network
  • Java / Jsp
  • Javascript /Jquery / React / Bootstrap / Web
  • JavaSE
  • 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
  • 二手车
  • 会计




Just Code Copyright © 2021.
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!
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.