Note : These instructions have been tested for the Raspberry Pi 3B+ and Raspberry Pi 4B. You can try these on older versions, but I have no guarantee that these instructions will work correctly.
To enable SSH in your Raspberry pi before actually booting it up, simply create a file named ssh
(with no extension) in the boot partition of your card.
Ref : https://www.raspberrypi.org/documentation/configuration/wireless/headless.md