Reputation: 781
I'm new to Git and GitHub/GitLab. I try to share my project to GitHub but it throws this exception:
Can't finish GitHub sharing process
Successfully created project 'LiveGame1' on GitHub, but initial push failed:
[email protected]: Permission denied (publickey).
Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I'm also able to clone a repository via internet link, but not via "[email protected]:/username/repository_name".
How can I fix this error and am I able to share my project directly to GitLab?
Upvotes: 13
Views: 35445
Reputation: 637
I have had a similar issue where I could not pull changes with SSH git, and solved the issue by adding SSH Configuration in Intellij.
Steps:
I hope it helps someone
Upvotes: 1
Reputation: 31
I solved it by running cat ~/.ssh/id_rsa.pub command, copied the result and in Github/settings/ssh and gpg keys added "new ssh key" and pasted the result there and save then run again "git push -u origin main" and it worked.
Upvotes: 0
Reputation: 690
There are loads of suggestions here How to solve Permission denied (publickey) error when using Git? and here Git gives me a “Permission Denied” error when writing files that I am pulling depending on the OS.
For me on Windows in IntelliJ the solution has been the one which is mentioned here: Can't access git using SSH keys.
I edited the ssh_config-File within the git-Installation, which IntelliJ uses with the Host of the sources and all worked.
File e.g.:
C:\Program Files\Git\etc\ssh\ssh_config
Change within the file e.g.:
Host bitbucket.org
IdentityFile C:\Users\User\.ssh\id_ssh
Edit: As mentioned in a comment (for Linux), it is also possible on Windows, to add a config file in your lokal user home directory: C:\Users\<USER>\.ssh\config
with the mentioned hostname(s) from above. This may be the better solution, if you are using multiple git-Installations or don't have access (due to missing admin-permissions) to your git-Installation.
Upvotes: 7
Reputation: 6608
I'm using Windows 10 and PuTTY authentication agent (with password protected SSH key) and this worked for me - for my Bitbucket and Github accounts where I uploaded my SSH key.
Steps to integrate 'SSH' key in Intellij -
- Open 'PuTTYgen' application.
- Click on 'File > Load private key'.
- Choose your .ppk file from directory.
- Click on 'Conversions > Export OpenSSH key'.
- Save the file in 'C:\Users\(your username)\.ssh' folder with 'id_rsa' name.
- Open Intellij.
- Click on 'File > Settings'.
- Expand 'Version Control'.
- Expand 'Subversion'.
- Click on 'SSH'.
- Select 'Private key' radio button.
- Select the generated file stored in 'C:\Users\(your username)\.ssh' folder.
- Click on 'Ok' button.
Test configuration: Click 'VCS > Git > Fetch'. If 'Fetch Successful' message displays, your configuration is successful
Upvotes: 4
Reputation: 2910
I can share a similar situation & answer regarding WebStorm.
I had previously stored a password for a different SSH
key, I added a new key (don't forget ssh-agent -s
if on e.g. Mac) but WebStorm didn't pick up on it.
No context is given within WebStorm for the upcoming error message, it's sadly the generic one from git
:
Push failed
<project>: git@<domain>: Permission denied (publickey).
Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
As mentioned and linked in several, several issues on JetBrains' IntelliJ tracker and/or forums (they led me here), WebStorm (and I assume IntelliJ as well) uses your SSH config dotfile under the hood. This implies using the native ssh
client (in previous versions, Settings » Version Control » git » SSH Executable to "native"
) or using a Configuration (Settings » Tools » SSH Configuration
s)
Thus, creating or editing your SSH
config
(e.g. Mac: ~/.ssh/config
) to include e.g.
Host <domain>
User git
IdentityFile ~/.ssh/<your private SSH key file, usually `id_...`>
will then make WebStorm pick up upon the git
remote
's domain
and prompt you for your password for the configured SSH key/SSH config item.
(Remember to replace placeholders marked with <placeholder>
above).
Upvotes: 0
Reputation: 2102
This article helped me get things squared away on my Windows 10 box:
https://richardballard.co.uk/ssh-keys-on-windows-10/
Note: The first section in the article should be titled "Enable the SSH Client in Windows" and should refer to getting the SSH Client enabled, not the server.
If you can get ssh -T [email protected]
working without prompting you for your password, as described in the above article, then you'll be able to push from IntelliJ just fine.
The keys were to:
ssh-add
that is invoked is the one provided in C:\Windows\System32\OpenSSH
git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"
When generating your keys with ssh-keygen
consider using the ecdsa algorithm as described here: https://www.ssh.com/ssh/keygen/
Also important was cleaning up anything else that was trying to do ssh outside of windows (like Putty). One problem I kept facing with 'invalid format' when trying to run ssh-add
I believe was caused by a different ssh-add
program on my path that was being used rather than the one from OpenSSH that ships with Windows.
Upvotes: 12
Reputation: 340
I have faced same problem and i generated public key for intelliJ in github account.
Settings -> Developer settings -> Personal access token
Then generate a new token for intelliJ by providing necessary scope and description.and copy the token key.
After that in intelliJ select Login via token access.Login by pasting the key in the form displayed.
Thank you
Upvotes: 4
Reputation: 5214
This question is too broad. Needs more details to clarify.
Run git remote show -n origin
(Assuming you are on branch origin
. -n
flag means "do not query remotes", which reduce the operating time for web requests.), you may see the remote URL.
In many common cases, for example on GitHub, Git URLs are in HTTPS protocols
https://github.com/<user>/<repo>.git
or SSH protocols
[email protected]:<user>/<repo>.git
If the field user
is not you, or one of your organizations, then you seems trying to contribute to someone's repository. Please fork and create a pull request to do so. You may need to change your local repo's remote url with command
git remote set-url <branch> <newurl>
If user
is you, then check if you have input your token correctly.
ssh -T [email protected]
.Update 1: There seems a typo in your question, [email protected]:/username/repository_name
. Note the first slash. I am not sure if it troubles.
Update 2: Check your Git credentials save in your IntelliJ IDEA in File -> Settings -> Version Control -> GitHub
Update 3: You are able to share it to GitLab too, just add one remote, for example run command git remote add gitlab <url>
.
Upvotes: 1