OpenSSH format
ssh-keygen -t rsa -f filename
PEM format
ssh-keygen -m pem -t rsa -f filename
this creates two files by the names
filename
filename.pub
Private key created is OpenSSH format by default, it starts and ends with
-----BEGIN OPENSSH PRIVATE KEY-----
...
...
-----END OPENSSH PRIVATE KEY-----
to convert this to PEM format
ssh-keygen -p -N "" -m pem -f filename
PEM format starts and ends with
-----BEGIN RSA PRIVATE KEY-----
...
...
-----END RSA PRIVATE KEY-----