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/id_rsa.pub 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 9 answers
stas.german April 24, 2014
HeartedHeart
2
If you don't have pbcopy, xclip or vim just type:
cat ~/.ssh/id_rsa.pub

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

pbcopy < ~/.ssh/id_rsa.pub

Copies it straight to the clipboard. Credit to BitBucket for that one.
etel
Mod
September 20, 2012
HeartedHeart
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.

Thanks,
Etel
jtansley September 20, 2012
HeartedHeart
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?

Thanks,
-James
jtansley September 20, 2012
HeartedHeart
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 id_rsa.pub
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 :)

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

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/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

Credit goes to github.