Generating SSH public/private key pair (OSx)

Generating a SSH public / private key pair for Mac OS X is as simple as that.

Before moving further ahead, lets first decide a passphrase.  passphrase is your special password for these files, even though its not mandatory to have one, but its strongly recommended to set for better security.
Good mix of upper lower characters, numbers, punctuations and spaces, all below 31 characters is the ideal one to go for it.

Now, that we've decided the passphrase, all remained to do is Generate the keypair !  To do so, fire below command in your terminal :

$ ssh-keygen -t rsa -C "yourname@yourdomain.ext"

Its strongly recommended to use a valid email address in above command, just in case.

After firing the above command, your terminal should respond with :

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

 What it meant is, /Users/#yourusername#/. ssh/id_rsa is the default location to save the key pair.  I would personally go for the same one rather than changing it to something different and remembering it.

So, assuming, you would go for the default path, just hit Return to go with default path.  Your terminal now should respond with :

Enter passphrase (empty for no passphrase):

As response states, you can proceed without giving passphrase by just hitting Return but then whats fun in it.  Right ?  So, lets go ahead and enter the passphrase we have had decided for, at the beginning of this article.

Your terminal should ask you to enter the passphrase again, for insuring the correctness of the same. 

Enter same passphrase again:

Enter the passphrase again and hit Return. After bit of a thinking (well, it still need to think, right !! lol ), program will respond to you with something like mentioned below.

Your identification has been saved in id_rsa.
Your public key has been saved in id_rsa.pub.
The key fingerprint is:
3c:fb:bf:4b:71:13:dd:d5:36:0d:94:6a:c7:23:97:75 #yourusername#@#yourmacname.local

Make a note, above given key fingerprint value is for demo only and that your actual output may differ from what given above.

On Side Note, since you just created a public/private keypair, and you are most likely to be using public key just in your next task, the question might come up, how would I copy my Public key in clipboard from this terminal,
well, pbcopy is for your help.

$ pbcopy < ~/. ssh/id_rsa.pub

Here, pbcopy utility will copy your public key into clipboard of your Mac.

There !! You're all set to use your keypair !! Happy Programming !

Add new comment