Multiple Unit control (or at least how it's typically done)
If you are wondering how you can get two locomotives to do the same thing when there's nobody in the second locomotive, this is done using a technique called Multiple Unit (MU) control in the US and Multiple Working in British practice.
While older locomotives and self-propelled carsets (especially outside the US, as the 27-pin AAR-standard MU connector was developed from the electrical MU system originally implemented by EMD in their wildly successful E and F series units) used a variety of incompatible systems for this, most modern locomotive designs worldwide have settled on the AAR system. This is in essence a discrete-electrical control system for all basic electrical functions on the locomotive -- the locomotive air braking system is handled through auxiliary air hoses that are connected along with the 27-pin MU jumper cables, while the MU connectors on newer locomotives also carry an AAR-standardized communications bus for advanced, computerized functions (such as detailed alarms).
As a result of this jumpering, each locomotive is effectively synchronized to the lead locomotive's commands -- the crew of the lead locomotive sets up the controls the way they want, and the MU cables transmit that setup to the rest of the consist. The "reverse" and "forward" lines are also transposed at certain points (in each jumper, and also in the connectors on the front of a locomotive) to allow locomotives to run correctly when MUed in while facing "backwards" -- in fact, it is rare (at least in North American freight practice) to see locomotive consists where there isn't at least one backwards facing locomotive.
From the operator's perspective -- they are sitting in the cab of one jumbo locomotive with the combined capabilities of all the locomotives MUed together behind them. Furthermore, the MU wires can be trainlined down passenger coaches to a cab car for push-pull passenger operations, or connected to a receiver box for remote control of the locomotive via radio -- this last one is used for Distributed Power for heavy trains or mountain grades as well as for improvising a Remote Controlled Locomotive out of a regular locomotive for yard use.
Sometimes, this isn't always the case, though
However, not every consist (rake over where the OP is) of locomotives is MUed throughout. Some older or smaller locomotives, as well as many engines dedicated to switching duty, may have incompatible (the Brits are plagued by this) or no MU controls, and will wind up "dead in train" if they need to be hauled a long distance. A locomotive can also end up "dead in train" if it needs to be moved somewhere else, but its motive power simply isn't needed to get the train from point A to point B -- too much motive power on the head-end of a train will cause it to derail or break-in-two from excessive drawbar forces. Finally, a locomotive may have broken down somewhere on the line; this means that the locomotive will be hauled "dead" to a shop so that it can be repaired.