Copy SSH key to clipboard

Posted September 20, 2012 802.2k views
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
1 comment

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
14 answers
If you don't have pbcopy, xclip or vim just type:
cat ~/.ssh/

and copy terminal output

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

$ clip < ~/.ssh/
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 :)

Easiest way I'm aware of is:

pbcopy < ~/.ssh/

Copies it straight to the clipboard. Credit to BitBucket for that one.

cat ~/.ssh/ | pbcopy

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.

install GIT GUI using : sudo apt-get install git-gui
open it using git citool to open git gui
click help > show ssh key > copy to clipboard

Show answer This answer has been marked as resolved by aswiniN.
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.

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?

Previous 1 2 Next