Generating SSH Keys on MacOSX

If you’ve been programming for a while now, even if you consider yourself a novice, you’ve probably run into the SSH (Secure Shell) protocol. Now, don’t get intimidated by this technical term, this is just another protocol like FTP (File Transfer Protocol) or HTTP (Hypertext Transfer Protocol). So look, you’ve already engaged with a protocol at one point in your dev career. In simple terms, protocol’s are just a set of instructions to complete a given task.

Now this post isn’t about SSH in itself, this post is about generating SSH keys. If you’ve ever connected to a remote server using SFTP (Secure FTP) using FileZilla or any other FTP client, then chances are you’ve run across generating SSH Keys. If you’re using any code repository like Github, BitBucket or GitLab – you’ve also likely generated SSH Keys.

To additionally preface this understanding of SSH keys, this process is essentially to provide a secure connection between a client computer and a server. Almost every protocol mentioned is related to this type of connection. Just something to keep in mind.

To generate both public and private SSH keys following the instructions provided on the Git website. Now there are loads of other resources and documentation on the internet but I found this to be the easiest to understand so really, use the documentation that works best for you.

List SSH Keys Command

Generating SSH Key Pairs

Viewing SSH Public Key

In addition to establishing a secure connection using SSH keys (because they are encrypted by using a complicated hash algorithm I can’t get into here), SSH Keys also provide a convenient way of connecting to a remote server without having to enter your username and password each and every time.

Alright now for for the meat of this post. There are essentially two main keys of importance – yes, the public and private key.

id_rsa.pub (public key)
id_rsa (private key)

Both keys are contained within your .ssh folder, notice the “.” (dot) before ssh, this means this is a system level directory.

So once you are for sure SSH keys have been generated, you can check them out by running the following command:


ls ~/.ssh/

After running the command, you should see the generated SSH key files

id_rsa

This is the SSH private key file stored on your computer

id_rsa.pub

This is the SSH public key file stored on the remote server you wish to establish connection