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

Comment restreindre l’accès à l’administration de WordPress par adresse IP

Note éditoriale : Nous percevons une commission sur les liens des partenaires sur WPBeginner. Les commissions n'affectent pas les opinions ou les évaluations de nos rédacteurs. En savoir plus sur Processus éditorial.

Vous souhaitez restreindre l’accès à votre zone d’administration WordPress pour des raisons de sécurité ?

Si vous avez une petite équipe, une bonne solution consiste à restreindre l’accès aux seules adresses IP utilisées par les membres de l’équipe.

Dans cet article, nous allons vous afficher comment restreindre l’accès à l’administration de WordPress par adresse IP, étape par étape.

How to Restrict WordPress Admin Access by IP Address

Pourquoi restreindre l’accès des administrateurs de WordPress par adresse IP ?

Si vous exploitez un site WordPress, vous devez prendre la sécurité de votre site au sérieux. Bien que le cœur du logiciel WordPress soit très sûr, vous pouvez faire plus pour vous protéger des pirates et des attaques par force brute.

Les pirates informatiques peuvent mettre votre site hors service et nuire à votre chiffre d’affaires et à votre réputation. Ils peuvent voler des données ou même distribuer des logiciels malveillants aux internautes et faire inscrire votre domaine sur la liste noire de Google, entre autres.

Une façon intelligente de bloquer les pirates et d’améliorer la sécurité de WordPress est de protéger votre zone d’administration de WordPress contre les accès non autorisés.

Si vous ou quelques utilisateurs/utilisatrices de confiance avez uniquement besoin d’accéder à la zone d’administration, une bonne façon de procéder est de limiter l’accès à wp-admin et à la page de connexion WordPress aux adresses IP de votre équipe.

Chaque membre de l’équipe se connectera à votre site WordPress en utilisant une adresse IP spécifique à chaque emplacement. Si vous bloquez l’accès à toutes les autres adresses IP, un pirate ne pourra pas accéder à votre site même s’il a découvert votre identifiant et votre mot de passe.

Au lieu de cela, ils verront apparaître le message d’erreur : ‘Interdit. Vous n’avez pas le droit d’accéder à cette ressource ».

Voyons comment restreindre l’accès à l’administration de WordPress par adresse IP.

Comment restreindre l’accès à l’administration de WordPress par adresse IP

La première chose à faire est de dresser une liste des adresses IP utilisées par toutes les personnes qui doivent se connecter à votre site WordPress. Si quelqu’un travaille depuis plusieurs Emplacements, alors vous devrez collecter l’adresse IP de chacun d’entre eux.

Ils peuvent connaître leur adresse IP en visitant un site comme SupportAlly.

Une fois que vous avez dressé votre liste, il vous faudra alors modifier un fichier sur votre site. Vous devrez utiliser un client FTP ou l’application de gestion de fichiers de votre fournisseur d’hébergement. Si vous n’avez jamais utilisé le FTP auparavant, vous pouvez consulter notre guide sur l’utilisation du FTP pour téléverser des fichiers sur WordPress.

Vous devrez utiliser le logiciel pour naviguer jusqu’au dossier /wp-admin/ de votre site. Une fois dans ce dossier, vous devez rechercher le fichier .htaccess. Il s’agit d’un fichier masqué, donc si vous ne pouvez pas le voir, il se peut que vous deviez activer l’option afficher les fichiers cachés dans votre logiciel.

Navigate to wp-admin and Locate .htaccess

Si ce fichier n’existe pas dans le dossier, vous devez créer un nouveau fichier et l’enregistrer sous le nom .htaccess dans votre dossier /wp-admin/.

Avertissement: Ne modifiez pas votre fichier racine .htaccess, ou vous bloquerez l’accès des internautes à l’interface publique de votre site ! Confirmez que vous modifiez le fichier /wp-admin/.htaccess.

Vous devez d’abord télécharger une copie du fichier sur votre ordinateur à titre de sauvegarde. Une fois cela fait, vous devrez modifier le fichier .htaccess et y coller le code suivant :

AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName "WordPress Admin Access Control"
AuthType Basic
<LIMIT GET>
order deny,allow
deny from all
# whitelist Syed's IP address
allow from xx.xx.xx.xxx
# whitelist David's IP address
allow from xx.xx.xx.xxx
# whitelist Amanda's IP address
allow from xx.xx.xx.xxx
# whitelist Muhammad's IP address
allow from xx.xx.xx.xxx
# whitelist Work IP address
allow from xx.xx.xx.xxx
</LIMIT>

Modifiez le fichier pour qu’il corresponde aux noms des membres de votre équipe, puis collez les adresses IP que vous avez collectées précédemment à la place de xx.xx.xx.xxx.

Une fois le fichier enregistré, seules ces adresses IP pourront accéder à l’administration de WordPress.

N’oubliez pas que si votre adresse IP est modifiée ou si vous essayez d’accéder à votre site à partir d’un nouvel Emplacement, vous serez bloqué dans la zone d’administration de WordPress. Vous devrez ajouter votre nouvelle adresse IP au fichier /wp-admin/.htaccess.

Nous espérons que ce tutoriel vous a aidé à apprendre comment restreindre l’accès à l’administrateur WordPress par adresse IP. Vous pouvez également consulter notre tutoriel WordPress sur la façon d’obtenir un certificat SSL gratuit pour votre site web ou consulter notre liste des extensions incontournables pour faire grandir votre site.

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.

Divulgation : Notre contenu est soutenu par les lecteurs. Cela signifie que si vous cliquez sur certains de nos liens, nous pouvons gagner une commission. Consultez comment WPBeginner est financé, pourquoi cela compte et comment vous pouvez nous soutenir. Voici notre processus éditorial.

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.

L'ultime WordPress Toolkit

Accédez GRATUITEMENT à notre boîte à outils - une collection de produits et de ressources liés à WordPress que tous les professionnels devraient avoir !

Reader Interactions

43 commentairesLaisser une réponse

  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!

    • WPBeginner Support says

      You would need to have your FTP or file manager show hidden files if you do not see it.

      Administrateur

    • WPBeginner Support says

      There are multiple methods to find your IP, one of the simple ones would be to use a site like supportally.com

      Administrateur

  2. Solace says

    I tried the .htaccess password protection method.

    It works, but I tried it on a site with Woocommerce, but then my customers weren’t able to log in.

    Just saying that because it seems no one has mentioned that it doesn’t work with sites that need customers to log in !

  3. Miguel says

    Hello, thank you for the tutorial. Unfortunately, I have not been able to make this .htaccess file to work correctly because it is denying access to the only IP address I included, my own… I am certain I copied your code exactly and I typed my IP correctly. The .htaccess file was saved under: /wp-admin/.htaccess

    Am I missing something? Thanks

  4. Emaan Ali says

    Hi Guys,

    I have blocked the wp-admin with .htaccess as mentioned in this article. But i am having one problem that my admin-ajax file is also being restricted on public site.

    My wordpress theme uses much of admin ajax functionality and that I have put the IP limitation access on wp-admin folder so its not accessible for all IP’s.

    Does anyone find the solution for this ? If so please share .

    Thanks in advance
    Emaan

  5. Len says

    Hi, This seems really a helpful one. Maybe you could help me. Instead of whitelisting an IP can we allow access for specific countries in .htaccess file? Hoping you can help me. Thank you very much.

  6. Scotty says

    Hi, This does work. I checked and am « forbidden » to login on any other computer. I can’t even see the login panel. However, I am still getting about 24 failed log in attempts per day from all different IP addresses. Any ideas how there getting around this? It’s some kind of brute force attack? Thanks, Scott.

  7. Sehrish says

    And how to allow access to only wordpress adminitrator ?What code i will write without any ip ? I just need to know a generic function that get admin related info.Becuse i have to restrict my plugin uploads from other user.And Whoever using this plugin i have to get its admin info to restrict contents from other and allow only to admin of website.

  8. Kim says

    I tried this (after previously successfully password protecting my wp-admin directory and fixing the redirect error per your other article), but then I get a pop-up asking for a user name and password for the « WordPress Admin Access Control ». What user name and password am I supposed to be using for this new pop-up? Neither the wordpress admin logon nor the wp-admin directory logon work for it.
    Thanks!

    • Kim says

      Oh, I believe I figured out the problem; seems to work as long as I make sure to have the added code at the very beginning.

  9. Jordyn says

    I have a big problem :(

    I did what you said about creating the .htaccess and putting in the code snippet. It didn’t work so I deleted the .htaccess file and now I can’t login to my dashboard! It’s just a white screen :( Please help!!!

    Thanks

      • Jordyn says

        All I did was create the file in my wp-admin folder and when it didn’t work I deleted it from the wp-admin folder. I’m not sure what happened but, after a crazy rabbit trail and many shots in the dark, I was able to correct the problem by adding to the top of my login.php file. I still don’t know what went wrong or why what I did fixed it…. but at least its fixed. I may try this again when I’m feeling brave.

  10. Raheem Khan says

    Hi WPB, I don’t think it will be working in Pakistan because every time we reset or turn of our DSL modem so the IP address automatically changes. if any other tip please reply me.
    Thanks

  11. andrew says

    hi, how to make .htaccess with dynamic ip (non static ip)
    my ip is always change xxx.xxx.xxx.12 xxx.xxx.xxx.453 xxx.xxx.xxx.076

    please help…

      • Joe says

        You can harden your wordpress install via .htaccess whitelisting even if you have a dynamic IP address. You can whitelist a range of IP addresses using a /24 or /16 range. While this allows more access than if you always knew the IP you wanted to allow, it still prohibits access from almost the entire internet.

        Just add /24 to the end of the allow from line to allow the whole class C subnet (256 IPs), or add /16 to allow the whole 65,536 range. i.e.

        allow from xxx.xxx.xxx.0/24

        will allow access to IP addresses from xxx.xxx.xxx.0 – xxx.xxx.xxx.255. and

        allow from xxx.xxx.0.0/16

        will allow access from IP addresses from xxx.xxx.0.0 – xxx.xxx.255.255

  12. Kyle says

    You say not to do the root site’s .htaccess file…why is that? Because you just want to limit access to the /wp-admin folder?

    So…if I wanted to have a WordPress site hosted externally but used as an internal company resource so that only people using IPs of our company could access it…if I edited the root folder’s .htaccess folder to only allow IPs from our domain…that would work the same way your /wp-admin fix is, but for the entire site, correct?

    • Editorial Staff says

      Yes Kyle, the reason why we said do not put this code in the root file because then it will limit your site access to only these IP as well. But if you are trying to make a site just for your company’s staff can access it only from work, then you would want to put the .htaccess file in the root folder.

      Administrateur

    • Alim Bolar says

      Can I limit access based on other criterias? Like I need only my laptop to access a particular folder.. I could access it from anywhere so it would be difficult to specify an IP as my internet access would be based on DHCP. Is there a unique identifier for every machine or something like that that can be used as a criteria?

Laisser une réponse

Merci d'avoir choisi de laisser un commentaire. Veuillez garder à l'esprit que tous les commentaires sont modérés selon notre politique de commentaires, et votre adresse e-mail ne sera PAS publiée. Veuillez NE PAS utiliser de mots-clés dans le champ du nom. Ayons une conversation personnelle et significative.