Copy SSH key to clipboard

Author: jtansley Date: September 20, 2012
Hello, I created an SSH key so that I can add it to Github. I am trying to copy the contents of /.ssh/ to the clipboard but I am getting errors in both PuTTY and the browser console. I tried installing xclip but that did not work. Any suggestions? I'm currently running an Ubuntu server 12.04 droplet. This should hopefully be my last SSH question! James
There are 10 answers
stas.german April 24, 2014
If you don't have pbcopy, xclip or vim just type:
cat ~/.ssh/

and copy terminal output
dan November 12, 2013
Easiest way I'm aware of is:

Copies it straight to the clipboard. Credit to BitBucket for that one.
etel September 20, 2012
Hi James!

I think the easiest way to copy the SSH keys is to open the public SSH key file (as you did) and manually copy and paste the key. This can be done in PuTTy by selecting your text with the left mouse button. Once it is selected, it should already be copied to your clipboard.

You cannot copy the text from the console viewer.

Please let me know if you continue having issues.

jtansley September 20, 2012
Hi Etel,

I really appreciate the assistance! Thanks for the reply. I am able to copy the SSH key to clipboard using PuTTY but GitHub doesn't like the key. I have a feeling that I'm not copying the entire SSH key. Double clicking the left mouse button will highlight/copy the line but only what you see on your line, not the entire line. This is the problem because even if I stretch my Putty window as wide as it allows, it seems that I'm still not copying the entire SSH key.

Is there a way to copy the entire line in the file, even if my console doesn't display it all?

jtansley September 20, 2012
Hello again,

I figured it out. Instead of nano, I should have used the vi text editor. Doh! Such a simple solution. Thanks again for all of your help!

For anyone else that ran into this issue, follow these instructions:

1. cd ~/.ssh
2. sudo vi
3. Click and hold down the left mouse button to highlight the entire SSH key but do not highlight any spaces after your email address at the end of the SSH key.
4. Paste into Github :)

trialtest11 September 20, 2012
Thank you for the update and the walkthrough! I'm glad you got it working :)
sneeker2000 August 20, 2013
Awesome, worked great, thanks. Was using nano too.
techytimo February 8, 2014
Thank you james, also worked for me after I used vi editor
sjnims+droplet August 5, 2014

You can also use xclip (assumes you're running a Debian based distro):

$ sudo apt-get install xclip
# Downloads and installs xclip. If you don't have `apt-get`, you might need to use another installer (like `yum`)

$ xclip -sel clip < ~/.ssh/
# Copies the contents of the file to your clipboard

Credit goes to github.

mastazi July 9, 2015

If you're running Windows, using Git Bash you can do this:

$ clip < ~/.ssh/