I remember in Fallout 3 and New Vegas that you could hack terminals controlling turrets to change a turret's targeting parameters (i.e. shoot your enemies and not you) but it seems that they've changed how things work in Fallout 4. I can run System Diagnostics and turn turrets off, but I don't know how to change the turret targets. I imagine it has something to do with the admin setting, but I don't know how to change that either.
You will need to get a copy of 'Total Hack Magazine', it comes with a Holotape to reprogram turrets.
One can be found in the wild wood cemetery - to the north east of Rotten Landfill. The Holotape is in the center of the graveyard under the big tree.
After you get that all you need to do is insert the Holotape into the terminal that controls the turrets then from their you can choose how you want it to react to you and enemies.
I remember this. You're not wrong; you do need an issue of total hack, that can be found somewhere near the top of the map. Not the exact top, mind you, but near there, in Wildwood Cemetery, underneath a large tree, found directly in the centre.
Also, the hack will ONLY work on turrets that are connected to each other via a wire, like you might have seen in the Coverga Assembly Plant, when you're asked to defeat those raiders. And regarding a previous statement saying you can't make them your allies, you're half right: You can use the Holotape to make them only target the enemies, using the Override parameters feature (or whatever it's called), and that will only make the turrets attack the enemies, rather than your allies. It's pretty sweet. I've almost never managed to get past many turrets without it.
EDIT: So, my answer is obviously wrong, I could not find a single of those magazines yet, therefore I do not know about this mechanic. I still leave the answer since there are a few informations which might be still useful
As far as i know, this feature is gone in Fallout 4. There are only a few terminals which you can use to "reprogram" connected turrets or robots. But you can't make them your allies, you can simply tell them to attack everyone. If they're done, you can disable them. The option in the menu is called always different, something like "Discard targeting parameters".
For example, this is possible on the race track near the boston fields, next to the village you can occupy for the minutemen.