How to Password Protect Your Folders On Linux

Linux is one of the most prevalent operating systems in the corporate world wherein users save their files or folders
By Mohit Raj
Mohit Raj
Mohit Raj
December 15, 2014 Updated: December 15, 2014

Linux is one of the most prevalent operating systems in the corporate world wherein users save their files or folders in our system which are private or contains secure information which should not be accessed by the outsider. This time one may feel the need of a password to protect your folder from unauthorized access.

Therefore, today we are going to make you learn that, “How to Password protect folder on Linux or Unix?”

Learn-How to Password Protect Folder On Linux Or Unix

The packages are available with a system that has SSH access, however if same is not available then the package has to be upgraded. The folders on your system can be restricted from access of other users and these changes can be done manually as well. You can follow these simple steps to password protect folder

  • Change the directory to the folder or create a new directory where one wants to put a password or want to protect it with a password. It can be the root of your folder or your webspace which you are making use to store the relevant materials
  • Then a username and password has to be created which will protect the folder stored in such changed or newly created directory. You may be asked to type the password and then press enter. While you are typing the password, nothing will appear on the screen to prevent onlookers on your screen from seeing anything
  • Then repeat the password and press enter
  • The above steps have thus created a user name and password to protect a certain set of folder and files within the system. The location of files should also be specified which have been protected with passwords.
  • Once above steps have been followed, type nano.htaccess and then press enter. The above command will open the Nano text editor to enable you to create or edit an .htaccess file
  • Right click the selected window with the mouse, and then paste it into the folder which has Nano text box within itself.
  1. A forward flash has to be added at the end of the line which is followed by .htpasswd.
  2. Then at the beginning of the line type AuthUserFile and then give a space.
  3. Then move ahead to a new line and type AuthTypeBasic.
  4. Start a new line to type AuthName “Protected folder”.
  • After the above steps you may exit and save the file by pressing CTRL and X.
  • Then open up the browser to look for a password protected URL. Before you take a step ahead password and username has to be fed into the system before you gain access to anything within the folder
  • This was it!

Advantages of configuring password manually

Following are the benefits:

  • The access to folders and also the files can be restricted
  • The access to different files can be restricted using different user name and password to make it difficult for the unauthorized user to have access to the same
  • The configuration which was available as default will not be overwritten to any of the changes made in the system
  1. Type the password and press enter to print the working directory file
  2. Then highlight the folder structure by clicking and dragging the mouse over it


This was all about Password Protect Folder on Linux or Unix, I am sure now your all queries have been removed now. Furthermore, if you have found this guide helpful and you think it is worth reading content then do share with your other friends and circle too. So, keep sharing and liking our content over social media.

Republished with permission from AllTechTricks. Read the original.
Mohit Raj