The reason could be that the your private key doesn’t actually is a RSA Private key i.e not starting with
-----BEGIN RSA PRIVATE KEY-----
Follow the following steps to fix the Invalid RSA Private Key issue:
Download OpenSSL 1.1, can be done via HomeBrew.
Run th following commands:
brew install openssl@1.1
echo 'export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc
Run the following command to generate rsa private key:
openssl genrsa -out /Downloads/private_key.pem 2048
The generated private key will have the following text now:
-----BEGIN RSA PRIVATE KEY-----