Skip to main content

Generating SSH Public and Private Keys

SSH keys are an easy way to authenticate access across machines and for automated processes. An SSH key is composed of two parts: a private key, and a public key. In order to access an external machine you'll need to send over a public key (pubkey). Here's how to do that.

On Mac and Linux:

Check first to see if keys are already available. Open the terminal and run cat ~/.ssh/ The key should look something like this:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDPmN5W+fIRqsPUkRNy2Y/+XycbQSeBsGi8jmFcz6SxVbXQjHI8kYxV2hOjhav+PUTYGOo9Zt67QxAkAJoHCIgc69r3KwZISJ7n32JOVgDY3ryZY3fBB52y8kbid
Zn2x1FhFPjI+HaBdDb7Pv+xAnITCGt7FpXlwOLeDSMxlhsVY+8zdSX79lPTlCVqY4hehN27jKxP9QoKUsSE= username@computer

If the key comes up, simply run pbcopy < ~/.ssh/ to copy the public key to your clipboard.

If the command comes up blank, you may need to generate ssh keys. Run ssh-keygen -t rsa (leave the file and the passphrase questions blank). Then run the pbcopy command above to copy the key to your clipboard.

On Windows:

To generate SSH keys on Windows you'll need to have OpenSSH Client installed. Go to the "Optional features" link in Settings>Apps>Apps & features and see if OpenSSH Client is listed; if not, click the plus sign next to Add a feature, select OpenSSH Client from the list, and install.

Open Command Prompt and type ssh-keygen. If a key already exists you'll be asked whether you want to overwrite the file (in most cases you don't and you can skip ahead to the key copy section). Hit enter to leave the passphrase blank.

The default folder the keys will be created in is \Users\<yourusername>\.ssh\. Navigate to that folder using the cd command and run clip < to copy the public key to your clipboard