可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have generated SSH keys for a new server installation according to the procedure outlined here. However, when I copy the contents of id_rsa.pub
to my keys list on GitHub, I get the error message "Key is invalid. Ensure you've copied the file correctly."
The generated key is valid, and I am copying it exactly as is (all in one line with no whitespace at the beginning/end).
Anybody have an idea what could be going on?
回答1:
I came here because I had the same problem. From your question, I realised that I was copying the contents from the wrong file (just the id_rsa
file, without the .pub
extension).
From a MAC:
vi ~/.ssh/id_rsa.pub
Copy exactly from the end (with be the last letter of your email domain extension) of the block of characters to the beginning, which starts with ssh-rs ...
If it doesn't work, you are surely not copying properly.
It worked.
If you are on Windows, use notepad and copy-paste as described above.
I hope that helped.
回答2:
Here are some steps that are not at all clear when copy/pasting your public key. (For the record, I used Putty Key Generator for my keys.)
- On the first line, enter ssh-rsa.
- Make sure you add one space after ssh-rsa
- When you copy/paste the key into the Key textbox it should preserve the \n characters (x0A). If you are using Notepad on Windows, you won't see these new lines until you copy the text to Github.
Notice on this screenshot, there's a space after ssh-rsa (See the cursor.) The public key text also includes three \n characters, so you can see the public key text bumps down to the next line three times in the textbox.
回答3:
I try several ways, but none of them helps(my os is ubuntu). Then I thought if I can print the content of ~/.ssh/id_rsa.pub by using command "more".
I sorry than I have no reputation to post images! when i have, i will post it!
Here is a url where you can see the image:
I copied the content from the command line, and it WORKED!!!
回答4:
Just for those looking in the future, another common issue is that word-wrapping. For example, if you run cat ~/.ssh/id_rsa.pub
it could wrap lines, thus adding extra \
characters at each line break. Remove these and your key should work fine.
回答5:
If you have indeed copied the content of your id_rsa.pub
key (in one continuous line), the result should look like (from The GitHub ssh help page):
The OP louism confirms a copy-paste issue:
- For a very obscure reason, copy-pasting from emacs removed the
\n
after ssh-rsa, and that was causing the problem. - Copy-pasting from vi solved the problem.
回答6:
Recommended by GitHub
Copying the SSH-KEY
:
I worked with xclip
to copy the id_rsa.pub
key, like so:
1. Install xclip
sudo apt-get install xclip
2. Copy with xclip
xclip -sel clip < ~/.ssh/id_rsa.pub
Good Luck.
回答7:
In windows,
Just Copy the naked key data from key file and remove new lines. Write this below things in dialogue box to solve your problem. ssh-rsa Key
NOTE : There is space between ssh-rsa and key
And you are done.
回答8:
If you using Sublime you can see ssh-key correctly. Check if there is any id_rsa.pub
ls -al ~/.ssh
If it is in place open it with sublime text
sudo subl /home/user_name/.ssh/id_rsa.pub
Then copy and paste your public ssh key.
回答9:
In my case, I had to add an extra white rule after my e-mail (after the entire key string) before it got accepted. I found this out by accident, after trying to copy my ssh key as entered on Gitlab.
pbcopy from my pub key straight form the command line didn't work. The copy from gitlab with the extra white rule at the end, did the trick.
回答10:
I just had this issue. Super frustrating. I figured my situation might have affected the casue of the problem. I am using a tablet, trying to setup the key on githubs site through my tablet browser (Chrome) and I am copying the key from an ssh app connected to my remote linux server.
What ended up happening is that somehow when I copied the key to the browser, it introduced a number of line breaks. Not only that, but it also removed a character from each point where a new line was inserted.
So to get it to work, I had to manually find each new line break, then hunt for that part of the key to find the missing character. I then added the character and removed the new line. After I hunted down each and every change, the key worked fine.
By the way, I did not add any new line breaks myself, such as the one mentioned by others after the ssh-rsa.
Hopefully this helps others. I have no idea why it happened. Silly that copying to the clipboard would alter the text copied. Oh, I also copied it right out of Vim.
回答11:
I was having the same issue, despite copying the public key from cat
output directly from the terminal (Cmder/ConEmu). It seems that the method that you use to copy the public key seems to make a difference. Here is a way to check:
$ ssh-keygen -l -f ~/.ssh/id_rsa.pub 4096 SHA256:...
Then paste the key that fails into a new file, and try to verify that:
$ ssh-keygen -l -f test.pub test.pub is not a public key file.
In my case I had been copying the key from terminal output using cat
; instead getting the key from vim
worked. Here is way to open the key in vim with word wrap enabled:
$ vim "+set wrap" ~/.ssh/id_rsa.pub
I suspect that the terminal emulator may have something to do with it as I haven't had this issue with Terminal.app.
回答12:
If you are using bash for windows as your terminal and you are copying via shift + highlighting + ctrl-c, then this solution might work for you:
- After copying the key and pasting it into notepad:
- Now go to Edit > Select All or Ctrl-A
- The large amounts of blue areas are whitespace. You need to delete them with either the backspace or the delete key. Leave the whitespace that in the green circles.
- You should now be able to copy and paste this edited version into github.