This is my proceedure, have done it many many times with about 98% success.
Get some fine grit, water based valve lapping compund. Do not use oil based.
First, score a line on the top of the crank and flywheel where the key alignment should be, important to be very accurate.
Next, paste the compund on the taper of the crank or inside the flywheel. Set flywheel on crank and lightly rotate round and round. Yep, you're lapping the flywheel to the crank to assure a good match. When you're satisfied its good, align the marks you previously scored, put on the nut and tighten to the proper torque. Leave the compound right where it is, the grit will further assist in holding it in place. This is why not to use a grease or oil based compound as it would make it slippery. The water base will dry and leave just the grit.
Can't take credit for this. Picked it from a web site about building B&S kart engines. This method is used by some of them for advancing the timing and eliminating the use of the alignment key. I know some of you hard core 2 cycle freaks may,,,,,,,freak out taking advise from 4 cycle racers but like I said, I've borrowed it many times. Got started using it because I hated telling Ryobi line trimmer owners that replacing a flywheel just wasn't practical cost wise. But since I found it works so well I now use it on any product that uses these cast in keys. Makes happy customers to save them a bunch of bucks.