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 on how to lock a file in a SharePoint document library by password.
Locking a file or folder is possible, when we share a document library files or folders with external users. Even though we can set a password for SharePoint Online document library files or folders with internal users, it won’t work for internal users.
Also, if anyone wants to unlock a file, only that user can open a 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 below-mentioned 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 to Anyone at Site Level
In this section, I will show you how to enable sharing settings to Anyone at a site level through a 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, Choose Anyone in External file sharing and click on Save.

This is how to enable external sharing to anyone at a site level in a SharePoint Online document library.
How to 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 “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, Click on the Deactivate button.

- It will redirect to the next page to confirm deactivation; click on the 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; select a file you want to share bylock.

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

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

- In Sharing settings, set a strong password for a file that needs to be shared with the users and Click on Apply.

- Then, it will again open a Share dialogue box, here I was giving an email id 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 below figure:

This is how to Share a file by locking it in a SharePoint Online document library.
Conclusion
Through this SharePoint tutorial, I have demonstrated how to lock a document library file in a SharePoint site. And also I have shown you the steps to lock a file within a SharePoint document library such as:
Steps:
- 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:
- Modern SharePoint Online List and Library Features
- Rename a Document Library in SharePoint
- Add a SharePoint Document Library in Microsoft Teams

Preeti Sahu is an expert in Power Apps and has more than 6 years of experience working with SharePoint and the Power Platform. As a Power Platform expert for Power BI, Power Apps, Power Automate, Power Virtual Agents, and Power Pages, she is currently employed with TSinfo Technologies. She is the author of the book Microsoft Power Platform A Deep Dive. She also made a big technical contribution to SharePointDotNet.com in the form of articles on the Power Platform. She enjoys traveling and spending time with her family in her spare time.