Found the error in my code. Root is not needed.

I changed the check at the beginning of my script that forced the user
to run the script as root. It now forces the user to run the script as
the user account. I’ve found that running the script as root actually
messes things up during the SSH key pair generation process, as it
creates the key pair for root, not the user.