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

Så här skyddar du din WordPress Admin (wp-admin) Directory med password

Webbplatsägare måste prioritera WordPress-säkerhet för att skydda sina känsliga uppgifter och upprätthålla sina användares förtroende. Ett mycket effektivt sätt som vi på WPBeginner gör detta på är genom att lösenordsskydda vår WordPress-adminkatalog.

Katalogen wp-admin är kontrollcentret för din WordPress-webbplats. Det är där du hanterar allt från innehåll till inställningar, vilket gör den till ett utmärkt mål för hackare. Genom att lösenordsskydda dina adminfiler skyddar du dem från attacker.

Den här artikeln innehåller en enkel guide för hur du enkelt kan lösenordsskydda din wp-admin-katalog och stärka webbplatsens säkerhet.

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

Varför ska du skydda din WordPress Admin Directory med password?

Genom att skydda din WordPress admin directory med password add to du ett extra lager av säkerhet till den viktigaste ingången till din WordPress website.

Din WordPress dashboard är det centrala navet på din site. Det är där du publicerar posts och pages, customize ditt theme, install WordPress tillägg, och mycket mer.

Ofta när hackare försöker komma in på din website gör de det via wp-admin-vyn med hjälp av en brute force-attack.

You can help protect your website against potential attacks by using security measures such as a strong password and limit login attempts.

För att vara ännu säkrare kan du också skydda wp-admin directory med ett password. När någon försöker komma åt ditt admin area måste de sedan enter ett användarnamn och password innan de någonsin kommer till WordPress login page.

Med detta sagt, låt oss ta en titt på hur du kan skydda din WordPress admin directory med password steg för steg.

Den första metoden rekommenderas för de flesta användare, och du kan använda snabblänkarna under för att hoppa direkt till den metod du vill använda:

Video Tutorial

Subscribe to WPBeginner

Om du föredrar skriftliga instruktioner är det bara att fortsätta läsa.

Metod 1: Skydda wp-admin med password med hjälp av Directory Privacy (rekommenderas)

Det enklaste sättet att skydda din WordPress admin directory med password är att använda din WordPress hosting provider ’s Directory Privacy app.

Först måste du logga in på din dashboard för webbhotell och klicka på alternativet ”Directory Privacy” i Files-sektionen på din webbplats cPanel-instrumentpanel.

Click on the Directory Privacy option in the Files section

Note: De flesta webbhotell som använder cPanel, gillar Bluehost, kommer att ha liknande steg. Din dashboard kan dock skilja sig något från våra screenshots, beroende på din hosting provider.

Nu kommer du till en vy som visar alla olika directories på din server. You need to find the folder that contains your website files.

För de flesta som äger en website hittar du den genom att clicka på ”public_html” foldern.

Click public_html

Då visas alla filer för website som du har installerat på din server.

Därefter måste du klicka på mappen med din websites domain name.

Click domain name folder

I den mappen ser du en wp-admin folder.

Istället för att klicka på mappnamnet måste du klicka på knappen ”Edit” bredvid mappen.

Click edit wp-admin folder

Då kommer du till en vy där du kan aktivera skydd med password.

Kontrollera bara boxen där det står ”Password protect this directory”. Om du gillar det kan du också ge din directory ett namn som ”Admin Area” för att hjälpa dig att komma ihåg.

Check password protect directory box

När du har gjort det måste du klicka på knappen ”Save”.

Då kommer du till en page där ett bekräftande message visas.

Confirmation message click back button

Nu måste du clicka på knappen ”Go Back” och du kommer till en vy där du kan skapa en användare som ska få tillgång till denna directory.

Du kommer att bli ombedd att enter ett användarnamn och lösenord och sedan bekräfta lösenordet. Se till att obs/observera användarnamnet och lösenordet på en säker plats, t.ex. i en app för lösenordshantering.

Create a User

Se till att du klickar på knappen ”Save” när du har gjort det.

Nu, när någon försöker komma åt din wp-admin directory, kommer de att uppmanas att enter användarnamnet och password du skapade ovan.

Password protect WordPress admin example

Metod 2: Lösenordsskydda wp-admin med hjälp av kod

Du kan också skydda din WordPress admin directory manuellt med password. För att göra detta måste du skapa två filer som heter .htpasswd och .htaccess.

Note: Det kan vara farligt att lägga till kod på din site WordPress. Även ett litet misstag kan orsaka stora error på din website. Vi rekommenderar därför denna metod endast för avancerade användare.

Skapa .htaccess-filen

Först öppnar du din textredigerare och döper den new filen till .htaccess.

Följaktligen måste du kopiera följande code snippet och add to filen:

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

Se till att du ändrar sökvägen för ”AuthUserFile” till den location där du uppladdar .htpasswd-filen och ändrar ”yourusername” till det användarnamn som du vill använda för att logga in.

Glöm inte att save filen när du är slutförd.

Skapa .htpasswd-filen

När du har gjort det måste du skapa en .htpasswd-fil.

För att göra detta öppnar du en textredigerare och skapar en fil som heter .htpasswd. Denna fil kommer att lista ditt användarnamn tillsammans med ditt password i ett krypterat format.

Det enklaste sättet att generera det krypterade passwordet är med en htpasswd generator.

Du behöver bara enter användarnamn och password, välja format för kryptering och clicka på knappen ”Create .htpasswd file”.

Create htpasswd file

Generatorn htpasswd kommer att displayed en rad text som du måste klistra in i din .htpasswd-fil. Se till att du sparar filen när du har gjort det.

Uppladdning av .htaccess och .htpasswd till wp-admin Directory

Det sista steget är att uploada båda filerna du skapade till wp-admin foldern på din website.

Du måste ansluta till ditt WordPress hosting account med hjälp av en FTP-klient eller det online filhanteringsverktyg som tillhandahålls av din hosting provider. För mer detaljer, se vår guide för nybörjare om hur du använder FTP för att uploada filer till WordPress.

För denna tutorial kommer vi att använda FileZilla eftersom det är gratis och fungerar på både Mac och Windows.

När du har anslutit dig till din website ser du filerna på din dator i det vänstra fönstret och filerna på din website till höger. Till vänster måste du navigera till den location där du saved .htaccess- och .htpasswd-filerna.

Sedan, till höger, måste du gå till wp-admin directory för den website du vill skydda. De flesta användare behöver dubbelklicka på mappen public_html, sedan mappen med deras domain name och sedan wp-admin-mappen.

Nu kan du välja de två filerna till vänster och klicka på ”Upload” från högerklickmenyn eller helt enkelt dra filerna till det vänstra fönstret.

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

Nu kommer din ”wp-admin” directory att vara skyddad med password.

Felsökning av lösenordsskydd för wp-admin

Beroende på hur din server och website är konfigurerad finns det en risk att du kan runka på WordPress error. Dessa error kan fixas genom att noggrant lägga till kod i din .htaccess-fil.

Note: Detta är .htaccess-filen som finns i din huvudsakliga website-mapp, eller ej den som du uploadade till mappen ”wp-admin”. Om du har problem med att hitta den kan du läsa vår guide om varför du inte hittar .htaccess och hur du hittar den.

Fixa felet Ajax fungerar inte

Ett av de vanligaste felen är att Ajax-funktionaliteten slutar fungera på front end av din site. If you have WordPress plugins that require Ajax, such as live Ajax search or Ajax contact forms, then you will notice that these plugins will not work anymore.

För att fixa detta, add helt enkelt följande kod till .htaccess-filen som finns i din wp-admin folder:

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

Fixa 404-felet och felet med för många redirects

Två andra error du kan råka ut för är 404 error och too many redirects error.

Det enklaste sättet att fixa dem är att öppna din huvudfil .htaccess som finns i din website directory och add to följande kodrad före WordPress-reglerna:

ErrorDocument 401 default

Bonus: Bästa guiderna för WordPress för wp-admin-säkerhet

Vi hoppas att den här artikeln har hjälpt dig att lära dig hur du lösenordsskyddar din WordPress-adminkatalog (wp-admin). Du kanske vill se några ytterligare guider om hur du gör ditt adminområde säkrare:

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.

Avslöjande: Vårt innehåll stöds av våra läsare. Det innebär att om du klickar på några av våra länkar, kan vi tjäna en provision. Se hur WPBeginner finansieras, varför det är viktigt, och hur du kan stödja oss. Här är vår editoriala process.

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.

Den ultimata WordPress-verktygslådan

Få GRATIS tillgång till vår verktygslåda - en samling WordPress-relaterade produkter och resurser som varje professionell användare bör ha!

Reader Interactions

205 kommentarerLämna ett svar

  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. Dayo Olobayo says

    I’m not very technical but I’m glad you included the option for using the Directory Privacy app. That sounds much easier than creating those .htaccess files. Thank you.

  3. 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.

      Administratör

    • WPBeginner Support says

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

      Administratör

  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 :)

      Administratör

    • 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.

      Administratör

  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

      This would show the same prompt for users trying to log in using the wp-login.php

      Administratör

    • WPBeginner Support says

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

      Administratör

  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.

      Administratör

  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.

      Administratör

  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

      Administratör

    • 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.

      Administratör

  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

      Administratör

    • 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

      Administratör

  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

      Administratör

  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

      Administratör

  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

      Administratör

  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.

      Administratör

      • 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,

Lämna ett svar

Tack för att du väljer att lämna en kommentar. Tänk på att alla kommentarer modereras enligt våra policy för kommentarer, och din e-postadress kommer INTE att publiceras. Vänligen använd INTE nyckelord i namnfältet. Låt oss ha en personlig och meningsfull konversation.