Use /unlock then use /cpublic.
You can lock chests, doors, trapdoors, fence gates, furnaces, dispensers, and droppers.
Why not enderchests? Enderchest contents are per-player, so if you have stuff in an enderchest, someone else will see other stuff in they’re enderchest.
/passlock password or /cpassword password
To use this command you must first /unlock your item.
The password command will lock your item and add a password that needs to be used to unlock it once per login. The password can be anything that you will easily remember. You can give it to anyone to get into your chest/furnace/door.
Use /cmodify [Person’s name] then hit the chest/door/furnace/dispenser. This applies to other lockable things.
You can use /lock to protect your chest/door/furnace/dispenser, then click on the item that you want to lock.