If you enable ssh or configure wifi settings using the Raspberry Pi Imager it creates the shell script firstrun.sh on the fat partition. This script is launched using the systemd.run option set in cmdline.txt. This script will enable the ssh service, copy over wifi settings to the ext4 partition, change cmdline.txt so it is no longer run and then reboot the pi. You could take this script and extend it to do anything you would like including copying over ssh keys.