SharePoint document library allows us to set the password while sharing files. As a result, we can secure our files. In this SharePoint Online tutorial, I will show you step-by-step instructions for locking a file in a SharePoint document library using a password.
Locking a file or folder is possible when we share a document library, a file, or a folder with external users. Even though we can set a password on SharePoint Online document library files or folders for internal users, it won’t work for them.
Also, if anyone wants to unlock a file, only that user can open the file and view it by entering the password.

Lock a File in a SharePoint Online Document Library
To lock a file within a SharePoint document library and share it with users, follow the steps:
- Enable Sharing Settings to Anyone for the User Site
- Deactivate the Limited-access user permission lockdown mode
- Share a file by locking in a SharePoint Online document library
Enable Sharing Settings for Anyone at the Site Level
In this section, I will show you how to enable sharing settings for Anyone at a site level through the SharePoint admin center.
By default, external sharing will be enabled for anyone at a SharePoint Tenant level.
- Open a SharePoint admin center, expand Sites, and click on Active sites.

- Search and select a site for which we need to enable sharing settings to anyone.

- In the Settings tab, select Anyone in External file sharing, then click Save.

This is how to enable external sharing to anyone at a site level in a SharePoint Online document library.
Check Create a SharePoint Document Library in Power Automate
Deactivate Limited-access User Permission in Lockdown Mode
Now, I will show you the next step, i.e., deactivating limited access user permissions lockdown mode in a SharePoint Online site.
When the Limited-access user permission lockdown mode is enabled, permissions for users in the “limited access” permissions level (such as Anonymous Users) are reduced, preventing access to Application Pages.
- Open a SharePoint Online site, Select Site information under Settings, and click on View all site settings.

- Select Site collection features under Site Collection Administration on the Settings page.

- Go to Limited-access user permission lockdown mode, and click on the Deactivate button.

- It will redirect to the next page to confirm deactivation; click on Deactivate this feature.

This is how to deactivate the limited-access user permission lockdown mode under site collection administration.
Share a File by Locking in a SharePoint Online Document Library
Now, I will explain how to share a file with file locking in a SharePoint Online document library.
- Open a SharePoint Online document library, then select the file you want to lock.

- Click on the Share option, which is present next to the selected item or in the command bar.

- Then, a Share dialogue box will appear; click on Sharing settings.

- In Sharing settings, set a strong password for the file you want to share with users, then click Apply.

- Then it will open the Share dialogue box again, where I was entering the email IDs of external users.

- Whenever a user tries to open a SharePoint document library file, it will ask to enter a password to unlock it, as shown in the figure below:

This is how to share a file by locking it in a SharePoint Online document library.
Conclusion
In this tutorial, we learned how to lock a file in a SharePoint document library. To do so, we need to follow the steps below:
- Enable Sharing Settings to Anyone for the User Site
- Deactivate Limited-access user permission lockdown mode
- Share a file by locking in a SharePoint Online document library
You may also like the following tutorials:
- Rename Subfolders in a SharePoint Document Library Using Power Automate
- Power Apps Upload File to SharePoint Document Library
- How to Delete Files Older than 3 Years from SharePoint Document Library Using Power Automate

After working for more than 18 years in Microsoft technologies like SharePoint, Microsoft 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (12 times). I have also worked in companies like HP, TCS, KPIT, etc.