Los hackers y otros actores maliciosos a menudo intentan entrar en los sitios web de WordPress a través del área de administración. Por eso es tan importante proteger el área de administración de WordPress.
Si tienes un equipo pequeño, una buena solución es restringir el acceso de administrador sólo a las direcciones IP utilizadas por los miembros del equipo. Esto puede evitar que los hackers entren y es uno de nuestros principales consejos de seguridad de WordPress.
En este artículo, le mostraremos cómo restringir el acceso del administrador de WordPress por dirección IP, paso a paso.
¿Por qué restringir el acceso de administrador de WordPress por dirección IP?
Si tiene un sitio web WordPress, debe tomarse en serio la seguridad de su sitio web. Aunque el núcleo de WordPress es muy seguro, hay más cosas que puedes hacer para protegerte de los hackers y los ataques de fuerza bruta.
Los piratas informáticos pueden tumbar su sitio web, además de dañar sus ingresos y su reputación. Pueden robar datos o incluso distribuir malware a los visitantes de su sitio web y hacer que Google y otros organismos incluyan su dominio en una lista negra.
Una forma inteligente de bloquear a los hackers y mejorar la seguridad de WordPress es proteger su área de administrador de WordPress de accesos no autorizados.
Si solo usted o unos pocos usuarios de confianza necesitan acceder al área de administrador, una buena forma de hacerlo es limitar el acceso a wp-admin y a la página de acceso a WordPress a las direcciones IP de su equipo.
Cada miembro del equipo se conectará a su sitio WordPress utilizando una dirección IP específica para cada ubicación. Si bloquea el acceso a todas las demás direcciones IP, un hacker no podrá acceder a su sitio web aunque haya descubierto su nombre de usuario y contraseña.
En su lugar, verán el mensaje de error Prohibido. No tiene permiso para acceder a este recurso’.
Veamos cómo restringir el acceso al administrador de WordPress por dirección IP.
Cómo restringir el acceso de administrador de WordPress por dirección IP
Lo primero que debe hacer es confeccionar una lista de las direcciones IP que utilizan todas las personas que necesita para acceder a su sitio web de WordPress. Si alguien trabaja desde varias ubicaciones, tendrás que recopilar la dirección IP de cada una de ellas.
Pueden conocer su dirección IP visitando un sitio como SupportAlly.
Una vez que hayas hecho tu anuncio / catálogo / ficha, tendrás que editar un archivo en tu sitio web. Tendrás que usar un cliente FTP o la aplicación de gestión de archivos de tu proveedor de alojamiento. Si no has usado FTP antes, entonces puede que quieras ver nuestra guía sobre cómo usar FTP para subir archivos a WordPress.
Deberá utilizar el software para navegar hasta la carpeta /wp-admin/
de su sitio web. Una vez allí, busque el archivo .htaccess
. Se trata de un archivo oculto, por lo que si no puede verlo, es posible que tenga que activar la opción de mostrar archivos ocultos en el software.
Si ese archivo no existe en la carpeta, entonces debe crear un archivo nuevo y guardarlo con el nombre .htaccess
en su carpeta /wp-admin/
.
Advertencia: No edite su archivo raíz .htaccess, ¡o bloqueará a los visitantes del front-end de su sitio web! Asegúrese de que está editando /wp-admin/
.htaccess.
Primero debe descargar una copia del archivo a su ordenador como copia de seguridad.
Una vez hecho esto, tendrá que editar .htaccess
y pegar el siguiente código en el archivo:
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>
Edita el archivo para que coincida con los nombres de los miembros de tu equipo y, a continuación, pega las direcciones IP que has recopilado antes para sustituirlas donde dice xx.xx.xx.xxx
.
Una vez guardado el archivo, solo esas direcciones IP podrán acceder al administrador de WordPress.
Recuerde que si su dirección IP cambia o intenta acceder a su sitio web desde una nueva ubicación, se bloqueará el acceso al área de administrador de WordPress. Deberá añadir su nueva dirección IP al archivo /wp-admin/.htaccess
.
Esperamos que este tutorial te haya ayudado a aprender cómo restringir el acceso al administrador de WordPress por dirección IP. Puede que también quieras ver nuestro tutorial de WordPress sobre cómo limitar los autores a sus propias entradas en la administración de WordPress o qué hacer cuando se bloquea la administración de WordPress.
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.
John
My wp-admin folder doesn’t contain an .htaccess file. What am I missing.
WPBeginner Support
You would need to have your FTP or file manager show hidden files if you do not see it.
Administrador
Mukund
How to find my ip address for hiding wp-admin folder?
WPBeginner Support
There are multiple methods to find your IP, one of the simple ones would be to use a site like supportally.com
Administrador
Chris
You have to enable
module authz_groupfile
“sudo a2enmod authz_groupfile”
and restart apache
Rajat Shankhdhar
Not working for me. Code restricting admin to get access even I put the ip in a whitelist.
Rostyslav
After this line, you must put a condition for permission to allow php files to prevent conflicts:
allow from all
Solace
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 !
Miguel
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
Miguel
I must add that I am working on a localhost installation.
WPBeginner Support
Hi Miguel,
Instead of your IP address, try adding 127.0.0.1
That’s your localhost IP address. If adding the IP alone doesn’t work, then add the following line before the above code:
Require local
Administrador
Pankaj Murthalia
how to block the access to wp admin???
Emaan Ali
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
Len
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.
Bridget
Thanks! This was the only solution that worked for me after trying so many
Scotty
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.
WPBeginner Support
Yes quite possibly. Make sure your .htaccess password is a difficult one.
Administrador
Scotty
Thanks. Your site has been very helpful. If you have moment maybe you could answer one more question. I followed your tutorials — and they worked. I blocked access to my admin folder with htaccess and added a password on top of that. I tested and even if people were to break the password, which they haven’t, they wouldn’t have access to the folder from any IP address except mine. However, I’m still getting about 12 failed logins per day. Any ideas what is happening and where to go to fix it? I was hacked once, but cleared the files out of my uploads folder.
Scotty
NVM: This page answered my question for now. Great info
https://www.wpbeginner.com/wp-tutorials/11-vital-tips-and-hacks-to-protect-your-wordpress-admin-area/
Sehrish
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.
Praveen
Many Many thanks sir, I have test this on my localhost system it works very well.
Kim
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
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.
Jordyn
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
Editorial Staff
That’s a fairly unlikely outcome. You deleted the .htaccess file in your /wp-admin/ folder correct?
Administrador
Jordyn
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.
Jordyn
it erased the code snippet it was supposed to say “…by adding “” to the top…”
Jordyn
less than sign ? ob_start(); ? greater than sign
Peter
First I did not manage to make your password protect work
https://www.wpbeginner.com/wp-tutorials/how-to-password-protect-your-wordpress-admin-wp-admin-directory
at least this one works.
It is interesting, that I wp-admin page gets into an infinite redirect when I enter a wrong IP address, not my one.
The infinite redirect seems to be hence an authorization problem.
Raheem Khan
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
Editorial Staff
You should look at our tip for password protecting the wp-admin directory.
Administrador
awan
yes it can be done on https, it’s just .htaccess
wpbeginnerfan
Can this be done on https sites? I can’t get it to work.
andrew
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…
Editorial Staff
Then this solution is not for you.
Administrador
Joe
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
Kyle
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
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.
Administrador
Kyle
Fantastic…thank you for the quick reply!
Bill
Why just limit GETs? You might want to limit POSTs as well!
Darrin
Nice tip. I will be doing this.
Alim Bolar
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?