Basically, you have to put your 27″ iMac in Target Display mode, which can be turned on and off by pressing the CMD + F2 keys . When your iMac is in Target Display mode, your computer dedicates the display to the computer connected by the Mini DisplayPort adapter while the system is running (but not responding to any keyboard or mouse calls).
The adapter you need to connect another Mac to your 27-inch iMac is a Mini DisplayPort cable with both male ends . As the document shows, the question of whether the 27-inch iMac with Core i5 would work is clear: any 27-inch iMac seems to work. But that’s not the case with the 21.5-inch iMac.