openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:keysize -out file
If an encrypted key is desired, use the -aes-256-cbc option.
openssl req -new -sha256 -key private_key -out filename
openssl req -key private_key -x509 -new -days days -out filename