Open a command line (or terminal window) and type the following command:
ssh-keygen -t ed25519
Alternatively, you may use an RSA key ("-t rsa").
SSH-keygen asks for the location of the key (usually in ~/.ssh, the suggested file name is useful) and a password for the key. The key password should be set for security reasons.
Two files are generated: the private and the public key, the latter has the extension ".pub" and can be displayed as follows (if you have accepted the suggested file name)
or for RSA keys:
When creating a new virtual machine, copy the contents of the .pub file to the fiels "SSH public key".