A protecting circuit using GPIO of the BeagleBone (Black or Green)
I prefer the opto version. It gives better isolation, especially if the 5V supply is separate from the micro board supply. I agree with Marko that the load resistor should be on the collector side of the output transistor. Of course that means the output is inverted.  I once needed to use the configuration you show. I made it work, but had to do some changes. This is what I ended up with.

First you need a bigger resistor in the emitter. I used 10K. I also used a 4N32 which has a Darlington pair output. This was needed because the transfer ratio was too low on a normal single transistor output.  It didn’t drive even a 10K to logic levels reliably.

The next problem is that sometimes the optos started having some leakage current and the output voltage would start creeping up from 0V when it was not being driven.  Often this didn’t happen until it was in the field for a while. The 4N32 brings out the base of the transistor pair to a pin. Putting a 3.3M resistor from that pin to ground solved the leakage issue.  Even after all that, I only got it to work reliably with Fairchild 4N32.  I sometimes had problems with other brands.

Based on the potential problems, the inverting version with a 10K load resistor between the collector and 5V is a better solution.