Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPBカップ
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

WordPress管理者(wp-admin)ディレクトリをパスワードで保護する方法

編集メモ: WPBeginner のパートナーリンクから手数料を得ています。手数料は編集者の意見や評価に影響を与えません。編集プロセスについて詳しく知る。

WordPressの管理ディレクトリをパスワードで保護する方法を知りたいですか?

WordPressの管理ディレクトリにパスワード保護を追加することで、WordPressのセキュリティを向上させることができます。

この投稿では、wp-adminディレクトリを簡単にパスワードで保護する方法について説明します。

How to Password Protect Your WordPress Admin (wp-admin) Directory

WordPress管理ディレクトリをパスワードで保護する理由

WordPress の管理ディレクトリをパスワードで保護することで、WordPress サイトの最も重要なエントリポイントにセキュリティのレイヤーを追加できます。

WordPressの管理ダッシュボードは、あなたのサイトの中心的なハブです。投稿やページの公開、テーマのカスタマイズ、WordPressプラグインのインストールなどを行う場所です。

ハッカーがあなたのサイトに侵入しようとする場合、ブルートフォースアタックを使ってwp-admin画面から行うことがよくあります。

強力なパスワードや ログイン試行の制限などのセキュリティ対策を行うことで、潜在的な攻撃からサイトを保護することができます。

さらに安全性を高めるために、wp-adminディレクトリをパスワードで保護することもできます。そうすれば、誰かがあなたの管理エリアにアクセスしようとしたとき、WordPressのログインページにたどり着く前にユーザー名とパスワードを入力する必要があります。

それでは、WordPressの管理ディレクトリをパスワードで保護する方法を順を追って見ていきましょう。

ほとんどのユーザーには最初の方法が推奨されており、以下のクイックリンクから使いたい方法に直接飛ぶことができる:

動画チュートリアル

Subscribe to WPBeginner

もし、文章での説明がお望みなら、このまま読み進めてほしい。

方法1: ディレクトリプライバシーを使用してwp-adminをパスワードで保護する(推奨)

WordPressの管理ディレクトリをパスワードで保護する最も簡単な方法は、WordPressホスティングサービスのDirectory Privacyアプリを使用することです。

まず、ホスティングアカウントのダッシュボードにログインし、ウェブサイトのcPanelダッシュボードのファイルセクションにある「ディレクトリのプライバシー」オプションをクリックする必要があります。

Click on the Directory Privacy option in the Files section

注: BluehostのようなcPanelを使用しているほとんどのホスティングサービスでは、同様の手順があります。ただし、ホスティングサービスによっては、ダッシュボードがスクリーンショットと若干異なる場合があります。

サーバー上のすべてのディレクトリを一覧表示する画面が表示されます。あなたのサイトのファイルを含むフォルダーを見つける必要があります。

ほとんどのサイトオーナーにとって、これは「public_html」フォルダーをクリックすることで見つけることができる。

Click public_html

サーバーにインストールしたサイトファイルがすべて表示されます。

次に、あなたのサイトのドメイン名のフォルダーをクリックする必要があります。

Click domain name folder

そのフォルダーの中にwp-adminフォルダーがあります。

フォルダー名をクリックする代わりに、そのフォルダーの横にある「編集」ボタンをクリックする必要があります。

Click edit wp-admin folder

パスワード保護をオンにする画面が表示されます。

このディレクトリをパスワードで保護する」というボックスにチェックを入れるだけです。お好みで、ディレクトリに’Admin Area’のような名前をつけることもできます。

Check password protect directory box

それが済んだら、『保存』ボタンをクリックしてください。

確認メッセージが表示されるページに移動します。

Confirmation message click back button

Go Back’ボタンをクリックすると、このディレクトリにアクセスできるユーザーを作成する画面になります。

ユーザー名とパスワードを入力し、パスワードを確認するよう求められます。ユーザー名とパスワードは、パスワード管理アプリなど安全な場所に控えておいてください。

Create a User

本当に〜してもよいですか?

これで、誰かがあなたの wp-admin ディレクトリにアクセスしようとすると、上記で作成したユーザー名とパスワードを入力するよう求められます。

Password protect WordPress admin example

方法2:コードを使ってwp-adminをパスワードで保護する

WordPressの管理ディレクトリを手動でパスワード保護することもできます。そのためには、.htpasswdと .htaccessという2つのファイルを作成する必要があります。

注意:WordPressサイトにコードを追加することは危険です。小さなミスでも、サイトに大きなエラーを引き起こす可能性があります。この方法は上級ユーザーにのみお勧めします。

.htaccessファイルの作成

まず、お好みのテキストエディターを開き、新しいファイルの名前を.htaccessとします。

その後、以下のコード・スニペットをコピーしてファイルに追加する必要がある:

AuthName "Admins Only"
AuthUserFile /home/user/public_html/example.com/wp-admin/.htpasswd
AuthGroupFile /dev/null
AuthType basic
require user yourusername

AuthUserFile’のパスを.htpasswdファイルをアップロードする場所に変更し、’yusername’をログイン中に使用するユーザー名に変更することを本当に〜してもよいですか?

終了したらファイルを保存することをお忘れなく。

.htpasswdファイルの作成

それができたら、.htpasswdファイルを作成する必要がある。

これを行うには、テキストエディターを開き、.htpasswdというファイルを作成します。このファイルには、ユーザー名とパスワードが暗号化された形式で記載されます。

暗号化されたパスワードを生成する最も簡単な方法は、htpasswdジェネレータを使うことです。

ユーザー名とパスワードを入力し、暗号化形式を選択して「.htpasswdファイルを作成」ボタンをクリックするだけです。

Create htpasswd file

htpasswdジェネレータは、あなたが.htpasswdファイルに貼り付ける必要があるテキストの行を表示します。ファイルを保存したら、本当に〜してもよいですか?

wp-adminディレクトリへの.htaccessと.htpasswdのアップダー

最後のステップは、作成した両方のファイルをサイトのwp-adminフォルダにアップロードすることです。

FTPクライアントまたはホスティングサービスプロバイダーが提供するオンラインファイルマネージャツールを使用して、WordPressホスティングアカウントに接続する必要があります。詳細については、WordPressにファイルをアップロードするためのFTPの使用方法についての初心者ガイドを参照してください。

このチュートリアルでは、無料でMacでもWindowsでも使えるFileZillaを使います。

サイトに接続すると、左側のウィンドウにコンピューター上のファイル、右側にサイト上のファイルが表示されます。左側で、.htaccessと .htpasswdファイルを保存した場所にナビゲーションする必要があります。

次に、右側にある、保護したいサイトのwp-adminディレクトリに移動する必要があります。ほとんどのユーザーは、public_htmlフォルダーをダブルクリックし、次に自分のドメイン名のフォルダーをダブルクリックし、次にwp-adminフォルダーをダブルクリックする必要があります。

左側の2つのファイルを選択し、右クリックメニューから「アップロード」をクリックするか、左側のウィンドウにファイルをドラッグします。

Uploading the Files to Your Website's wp-admin Directory

これで「wp-admin」ディレクトリがパスワードで保護されます。

wp-adminパスワード保護のトラブルシューティング

サーバーやサイトの設定によっては、WordPressのエラーに遭遇する可能性があります。これらのエラーは、.htaccessファイルに慎重にコードを追加することで修正できます。

注意:これはメインサイトフォルダにある.htaccessファイルで、’wp-admin’ フォルダーにアップロードしたものではありません。.htaccessが見つからない場合は、.htaccessが見つからない理由と見つける方法をご覧ください。

Ajaxが動作しないエラーの修正

最も一般的なエラーの1つは、サイトのフロントエンドでAjax機能が動作しなくなることです。ライブAjax検索や Ajaxお問い合わせフォームなど、Ajaxを必須とするWordPressプラグインを使用している場合、これらのプラグインが動作しなくなることに気づくでしょう。

これを修正するには、wp-adminフォルダーにある.htaccessファイルに以下のコードを追加するだけです:

<Files admin-ajax.php>
    Order allow,deny
    Allow from all
    Satisfy any 
</Files>

404エラーと多すぎるリダイレクトエラーの修正

他に遭遇する可能性のあるエラーは、404エラーと リダイレクトが多すぎるエラーです。

これらを修正する最も簡単な方法は、サイトディレクトリにあるメインの.htaccessファイルを開き、WordPressルールの前に以下のコード行を追加することです:

ErrorDocument 401 default

ボーナス:wp-adminセキュリティのためのベストWordPressガイド

wp-adminディレクトリをパスワードで保護する方法はおわかりいただけたと思いますが、管理エリアをよりセキュアにするためのガイドをご覧ください:

この投稿がWordPressの管理(wp-admin)ディレクトリをパスワードで保護する方法を学ぶのにお役に立てば幸いです。また、無料メールドメインの取得方法や、専門家が選ぶ中小企業に最適なメールマーケティングサービスもご覧ください。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

情報開示 私たちのコンテンツは読者支援型です。これは、あなたが私たちのリンクの一部をクリックした場合、私たちはコミッションを得ることができることを意味します。 WPBeginnerの資金源 をご覧ください。3$編集プロセスをご覧ください。

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

究極のWordPressツールキット

ツールキットへの無料アクセス - すべてのプロフェッショナルが持つべきWordPress関連製品とリソースのコレクション!

Reader Interactions

204件のコメント返信を残す

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Mrteesurez says

    Thanks. I found it helpful.
    I want to ask if the methods are all offering the same level of security, I would prefer and recommend to stick to the first method as it seems easy and straight forward.

    Or is there any one that is better than the other ??

    • WPBeginner Support says

      These are different methods to achieve the same result so it would depend on your preference for which one you would use.

      管理者

  3. Mark says

    Is there anyway for hackers to gain access to this password and even change it, like in phpMyAdmin ?

    • WPBeginner Support says

      They would need access to your hosting provider or site files for this guide.

      管理者

  4. Salman says

    I have changed my login URL using the “WPS Hide Login” plugin. Lets say the previous URL ended in wp-admin/ and the new URL ends in hidden/ now how can I password protect this new URL?

    • WPBeginner Support says

      It would depend on what method you are using and how you changed the URL, as long as there is a file/folder in the new location you should be able to select that folder or change the path on line 2 of the htaccess method :)

      管理者

    • Jiří Vaněk says

      WPShide doesn’t create a new folder, I use that too. The wp-admin folder is still on the server and functional. So if you use WPSHide, secure the wp-admin folder exactly the same.

  5. Jiří Vaněk says

    A good practice is also to rename the WordPress administration URL and choose a different administrator username than ‘admin.’ Changing the URL makes it harder for attackers to locate the administration, and not using ‘admin’ as the administrator reduces the risk of a successful brute force attack.

    • WPBeginner Support says

      Having a username other than admin is definitely recommended but for changing the wp-admin url is not always recommended as that can cause trouble with some plugins as well as make troubleshooting more difficult.

      管理者

  6. Umer Yaseen says

    What if someone accesses our WordPress admin directory by entering mywebsite.com/wp-login.php instead of mywebsite.com/wp-admin. This method only protects wp-admin and not protects wp-login.php. So how it is useful?

    • WPBeginner Support says

      We’ll see if we can add a method for that type of server when we update this article :)

      管理者

  7. Rajah says

    The first method through cPanel worked like a charm. However, when I logout again from WP and login again it doesn’t ask again for the directory password. Is it meant to ask only once?

    • WPBeginner Support says

      Your cookies/cache will remember the login information. Normally the next time you start up your computer it will require you to log in again.

      管理者

  8. Izzy says

    The “Password Protect Directories” is not on my cPanel under “securitiy”, so I tried the manual way, but it doesn’t seem to work as it doesn’t ask for login when I open wp-admin…

    • WPBeginner Support says

      If you reach out to your hosting provider they should be able to assist and take a look if there’s any reason it wouldn’t be working.

      管理者

  9. Ahsan Ali says

    Thanks for your efforts!
    I used cpanel method it works fine but the problem is that the password prompt appearing on every page of my website!

    What i have to do so that it appear only at wp-admin page?

    • WPBeginner Support says

      It sounds like you may have password protected your public_html folder instead of the wp-admin folder. You would want to remove the current protection and attempt to set it up again

      管理者

    • WPBeginner Support says

      That would be where your WordPress folders are, you could either use FTP or your host’s file manager if they have one to get to your WordPress files.

      管理者

  10. CHHRIS says

    Please this settings works fine for me, but my problem is that am using woocommerce and yith woocoomerce my account page, so when ever users login to their my-account area they are often prompted to put the login details for my protected admin, how can i fix this?

    • WPBeginner Support says

      For that, you would want to remove this protection unless you wanted to give each user a login for the httpassword

      管理者

    • WPBeginner Support says

      It would depend on the specific error you are running into when trying to get to your admin area for how to solve the problem

      管理者

  11. Rahul Yogi says

    Hy buddy, i had tried cpanel method which doesnt work for me but manual method work as shown above.

    But i have one problem after going example.com/admin, i have to enter directory username and password but after after entering nothing happens means it does not redirect me to dashboard or anywhere. Just same page — shoing waiting for connection for example.com and get error too many redirect.

  12. Brian says

    Wow,

    You are a legend! Spent like 2hrs jumping from site to site to get this working… First site that mentioned the ErrorDocument 401 default. Works like a charm now

    Thanks

  13. Deb says

    Thanks so much – this is the first place I have found with all 3 bits of code that was needed – (I had the redirect problem). The code worked like a charm. I now have an extra layer of protection without adding another potentially vulnerable plugin.

  14. Garry says

    All I get after adding the above code in a .htacess file on /wp-admin folder is 500 internal server error.

    • WPBeginner Support says

      If the htaccess method is not working you could remove the code and then use the cpanel method for password protecting the directory

      管理者

  15. Colleen says

    I did this, followed the link for the error message and for some reason I don’t have a .htaccess file!

  16. Samwel says

    I followed the steps but i now can’t log in . It says “The server encountered an internal error or misconfiguration and was unable to complete your request.”

    even on refreshing the page the pop up to key in password does not re-appear help out

  17. maria hag says

    hi,

    i bought new name and i change the name of website and than save it . now i cant login to admin. it show me 404 erorr
    how can i change it
    please advise

    • WPBeginner Support says

      You would want to reach out to your hosting provider and they should be able to help you have your new domain point toward where your site is currently

      管理者

  18. taher says

    I have activated password protection to wordpress directory via c-panel but wordfence is unable to scan my site. Due to ajax issue.

    I tried fixing it by updating my wp-admin/.htaccess file with the provided code by you but wordfence is still unable to start a scan. What do you suggest?

    • WPBeginner Support says

      You may want to ensure your caching is cleared and if that error continues, reach out to Wordfence about their plugin

      管理者

  19. Amit Mukherjee says

    Enabling password protection of the wp-admin directory prevents me as logging in as the administrator. I get a page not found error. I cannot get to the login page. If I remove the password protection, I can login.

    What should I do. I am setting up a WordPress website for the first time.

  20. mary-anne J. says

    So how do you undo the password protect using the cPanel ..that is, I want to remove my password protection for the wp-admin directory

  21. Keri says

    I followed the instructions to add the password protection using c_panel.

    It works fine in IE 11 but doesn’t work in: Edge; Firefox; Chrome; or Opera.
    Any ideas?

      • Keri says

        I’m not sure what I missed, given that it worked in IE but not in the other browsers. I deleted the user to whom I had given access and added the same user back in and, “Voila!”, all is good.

  22. Valentin says

    > Upload this file outside your /public_html/ directory.

    Good advice—more generally: outside your DocRoot.

    > A good path would be: home/user/.htpasswds/public_html/wp-admin/passwd/

    That, however, doesn’t seem to be outside your DocRoot ;)

  23. pawan singh says

    hi syed, i followed your tutorial as i do always whenever i find a problem but i am facing this error continiously.

    ERROR –

    “401
    Unauthorized

    Proper authorization is required to access this resource!”

    1. I made htpassword file properly with user name and password.
    2. Edited main .htaccess file with proper code.
    3. Implemented this line in .htaccess file on topas first line
    ErrorDocument 401 default
    4. Add AJAX functionality code

    After doing all this i see additional popup box which need login details for wp-admin. – Success here

    But i’m not able to access my home page like example.com. popupbox appears again without calling /wp-admin. Please tell how to remove this 401 Error. I see that many bloggers asked this issue in comment section, but you didn’t reply. I hope you will soon address the problem.

    • WPBeginner Support says

      Hello Pawan,

      This could be because the password your entered is incorrect or your server couldn’t find the .htpasswds file. We will recommend you to retrace your steps to figure out what went wrong.

      管理者

      • Robbiegod says

        I am seeing the same issue. On subpages on my site, when I have my /wp-admin/ .htaccess password protecting my site, I get the user/pass pop-up box on pages on the front end.

        The temporary solution was to just remove the htaccess file from wp-admin. Now i am trying to put it back, so I’ll see what i can come up with and post back if i figure it out.

  24. Arinze Ifeanyi says

    Thank you for this. I worked really well especially that line “ErrorDocument 401 default” that prevented it from giving 404 error. I really dont miss tweet from you. My question now is, how can someone remove the password? And again, will the password be required upon users registration via a custom registration page?

  25. Rony Ahamed says

    after using this method now when i try to go in wp-admin its says me maintenance mood ( this mode is on in my wp dashboard ) .. so how can i use it ?

  26. Adrian says

    Do you have a method using IIS? I’ll be glad if you have. I’m very new to WordPress running in IIS server.

  27. pawan says

    hi how to change my cpanel default url like “www.example.com/cpanel” to “www.example.com/customized”
    there is nothing on the internet about this topic.

  28. Edgar says

    Hi my dear friends I have a problem. I want to make double autentification on my wordpress.But there is conflict in wordpress htacsess between wp default rules and this code:

    AuthType Basic
    AuthName “Password Protected”
    AuthUserFile path/to/.htpasswd
    Require valid-user
    Satisfy All

    I get error like 500 or error “this page is wrong”, but after delating wp default rules my code work.There is some conflict between wp code and my code! Can anyone take solution!

  29. Aurangzeb says

    A very nice approach, but I also suggest to go secure with https, because no matter how protected the admin panel is, with passwords, the passwords itself are not secure if it’s not https.

  30. Daljit Singh says

    Hey guys, my issue is related to this post but it is little different too.
    I need to password protect my wp-content folder in my hosting.
    I called my godaddy hosting and they said that it is not possible.
    But i need to password protect it.
    Can someone help me out please?

  31. Akhil says

    Password Protecting WordPress Admin with Permalink “Post Name” gives error error login page( Redirect too many times). How to solve?

  32. Harmony A-E says

    Can I do this for my wp-login?

    The wp-admin is password protected and gives out a 401 if some tries to exit the pop-up (so 0 access without the 1st password).

    But my wp-login allows access to a disfigured wp-login page if someone exits out of the pop-up.

  33. Frank says

    That’s a great article.

    However, I’d like to ask you how can I track the who visits the page (IP, etc) even though if they don’t type any username or password or type wrong ones. I can’t seem to find a way to do that.

    Please let me know.
    Thanks!

  34. Deivamoorthy says

    Thanks for this article. It is really helped me lot save the login form anonymous person. But, i have an issue on my site. Whenever the user visits and entering to the single post page it asks the user enter the username password, Even though they have didn’t accessed the wp -admin. it happens only in Mozilla browser. How to solve this?

  35. Toan says

    I has finished setting protect password for wp-admin folder. But i can not registered new account for guest. Because it apperance pop-up login require username/password.

  36. paras arora says

    sir actually i have changed my admin directory from example.com/wp-admin to example.com/abcde …how to password protect it now

  37. Sarah says

    Thanks for this valuable info.I have question I want to setup limit login Attempts if users fails 1st time then try after 24 hrs latter how to I make this on cpanel?

  38. RJ says

    Hi there I do password protect my wp-admin directory and I did add that code to my htaccess …but…it is still asking for authorization.

    Any suggestions?

  39. dipesh says

    i dont ve set password for wp-admin folder but still it shows authorization dialog .
    how to solve the issue,

      • Gaurav Agrawal says

        Hi, I am also facing the same problem. May I know what are the changes that have to be done in server configuration?

        Please let me know as soon as possible.

返信を残す

コメントありがとうございます。すべてのコメントは私たちのコメントポリシーに従ってモデレートされ、あなたのメールアドレスが公開されることはありませんのでご留意ください。名前欄にキーワードを使用しないでください。個人的で有意義な会話をしましょう。