While a transistor-based cable shutter release does the job, it has one drawback. Grounding the camera to Raspberry Pi can cause the machine or the camera to have a negative ground. This might lead to a higher total voltage difference and could damage either of them. One way to solve this problem is to separate the camera and Raspberry Pi circuits using optocouplers (or opto-isolators).
While it’s possible to use a MOC3021 or a similar optocoupler for this, you can also build a simple DIY opto-isolator using a white LED and an LDR (light-dependent resistor). Basically, you need to align both components, so the LED’s light beam hits the surface of the LDR as shown in the photo below:
For better results, you might want to put heat-shrink tubing around the components to improve light transmission and prevent accidental light streaks (as well as make the DIY optocoupler assembly more sturdy). The LDR acts as a simple circuit switch: when the light hits the LDR, its resistance drops, thus closing the circuit. It might not be an optocoupler in the true sense of the word, but it serves well this particular purpose.
Replacing transistors with opto-isolators also simplifies the overall design, and you can use the diagram above to wire the circuits.