One way is to use a body double of similar build and appearance to the actor. The similarity can be enhanced by use of makeup and prosthetic and careful cutting and composition of shots may be enough to preserve the illusion. For example showing a closeup composite shot when they are physically separate and then cutting to a shot where one actor's face is partially obscured for the interaction. For example in a hug it is often difficult to see both people's faces clearly from any angle even without careful shot composition.
Modern digital technology also makes this easier as it is now entirely possible to 'paste' one actors face onto another of reasonably similar appearance. This technique was used for the scene where Lena Headey appeared to walk naked through the streets on Game of Thrones. It is her face digitally composited onto a body double.
As mentioned digital technology also makes it reasonably easy to accurately replicate camera moves over an over again and advanced in processing power mean that composite shots can be processed quickly enough to be checked, at least in rough form on set so precise positioning and movements of actors can be refined on the fly and small discrepancies can be digitally massaged later.
Similarly careful rehearsing and aids such as marks on the floor, simple puppets and other reference points are more traditional ways to help and actor to get their movements precise enough to match up to another performance compposited in.
Motion capture can be used to allow digital doubles to be accurately matched to the movements of stand-ins. For example in Lord of the Rings a lot of the shots with Gollum are rotoscoped over Any Serkiss's real-time performance with the live actors rather than having them interact with empty space.
Similar techniques may be used when a stunt performer is used to double for an actor.