For me (Lenovo P2, Android 8.1/LineageOS 15.1) the TWRP procedure below worked although with one side effect. It may also work on Android 6.
Please note that it requires an unlocked bootloader, a custom recovery image (standard for custom ROMs), blanks the /data and internal /sdcard partitions and involves rooting - note that this may result in problems with some security-sensitive programs, such as banking/payment apps.
It is essentially this one for a different device, apart from the steps to mount storage and using a different zip (important); the screenshots are instructive. It is worth being familiar with the recovery program.
- Backup /data partition, including the USB mounted internal storage (which I think is /sdcard on my phone). I would also recommend syncing contacts, backing up WhatsApp to cloud ..etc. Back up the entire phone flash memory if you are not using a custom ROM/recovery.
I would advise studying/reading up a bit on this - I somehow failed to do /data properly, so had to reinstall and reconfigure all apps.
- Download the Magisk zip on this page or a newer one if you can find it (it may be possible to update it with newer Magisk files; or you can flash a newer Magisk version after rebooting the system and confirming the /data partition is unencrypted).
- Reboot into recovery (TWRP).
- Format the /data partition (for TWRP use the specific Format Data button under Wipe - see screenshot on first linked page).
- For TWRP reboot into recovery again so it definitely understands the /data partition is now no longer encrypted.
- Mount /data & /sdcard and move the Magisk zip to the sdcard area.
- Install the Magisk zip.
- Reboot System.
- Open Magisk Manager under the apps and configure Magisk Hide for any relevant apps. Magisk Hide settings may not survive a reboot on some filesystem implementations - worth checking as if you are blanking /data, that is also a good time to change filesystem on it if you want those settings persisted!
Side effect on Lenovo P2 is that the fingerprint sensor and settings do not work. (If I encrypt the data partition later from within the Android settings, then it works again.)