Useful SSH commands for working with public/private keys

Below are a list of some useful commands for working with public/private keys on a server over ssh. All of these were pulled from the bitbucket documentation on setting up SSH for Git here.

Test what version of SSH you are running, if any:

$ ssh -v

List the contents of your ~/.ssh directory:

$ ls -a ~/.ssh

Generate a public/private key:

$ ssh-keygen

Test if an ssh-agent is running (for you to load your newly generated keys to):

$ ps -e | grep [s]sh-agent

If an agent is not running then start it manually:

$ ssh-agent /bin/bash

Load a new identity into the ssh-agent management program using the ssh-add command:

$ ssh-add ~/.ssh/id_rsa

List the keys that the agent is managing:

$ ssh-add -l

Show a key so you can copy and paste it on a LINUX server:

$ cat ~/.ssh/id_rsa.pub

Copy and paste a key on MAC OS:

$ pbcopy < ~/.ssh/id_rsa.pub