This post shows how to generate public / private key pair.

To generate public/private key pair, simply run the following command:
$ ssh-keygen -t rsa

Following are step-by-step instructions:

1. Open your terminal window in your Linux, Mac, or Windows machine by typing terminal in the search box or spotlight.

2. Type the following command

ssh-key -t rsa

3. You should see a prompt like the following:

Generating public/private rsa key pair. 
Enter file in which to save the key (C:\Users\myuser/.ssh/id_rsa):

4. Press the return key and it will create a .ssh directory as below. Alternately you can define a different location for the key pair.

Created directory 'C:\Users\myuser/.ssh'. 
Enter passphrase (empty for no passphrase):

5. You will be prompted to type a password twice. The you will get confirmation of the creation of your keys:

Your identification has been saved in C:\Users\myuser/.ssh/id_rsa. Your public key has been saved in C:\Users\myuser/.ssh/id_rsa.pub. 
The key fingerprint is:
SHA256:gITKSpgtUIyyV14qKrFjFSSQvSFW6vylQGappLeWDmE 
somesystem\someuser@deviceid 
The key's randomart image is: 
+---[RSA 2048]----+ 
|.oo+=+o. | 
|= ..o=* . . | 
|==..S=.* o . | 
|==oB. B.. S | 
|=Eo.+. oS | 
|oo E o o | 
|. + o | 
| + | 
| . | 
+----[SHA256]-----+

Note that the private key is id_rsa. This is the key you should never share. id_rsa.pub is the public key. You share this key. Any data encrypted with your public key can only be opened with your private key.

Copying your key pair to a server

To copy your key to a server, user secure copy (scp) as follows:

scp ~/.ssh/id_rsa.pub xyz.com:~/.ssh/authorized_keys