SourceTree + OpenSSH error: Could not open a connection to your authentication agent - openssh

I've been trying to add a private key for a while now using SourceTree and OpenSSH. I have tried all the solutions and derivations proposed in this answer to no avail. I've tried all variations of
eval `ssh-agent -s`
ssh-add
that I've found. I disabled all firewalls, antivirus, and even tried it in netorked safe mode. The first command runs fine, and the agent gets a pid, but the ssh-add command throws the error in the title every time. I've also used different names for the .pem file, including the original name and location, username/.ssh/id_rsa.pem (some people had had problems due to the file name), etc., but nothing changes.
I can connect manually to the repository by using the command
ssh -i /route/to/key/key_name.pem ubuntu#serverip
but I want to be able to use it to push changes to the repo through Git. I'm really stumped on this one, and I'm by no means an expert. Can anyone think of another reason for this?

In the end I had to give up on using OpenSSH for Windows. I installed PuTTY, transformed the .pem key into a .ppk with PuTTYgen, and added the private key with SourceTree without trouble.

Related

How to fix SSH / Git connections after windows update broke them? Issue seems to be related to ssh-agent

I use Windows 10 / PyCharm / GitHub Desktop as my developer environment.
I use ssh keys to access my remote git repository. Everything on my computer functioned perfectly a week ago, but now it does not.
I have Github Desktop installed, and that is not affected. I can use Github Desktop to pull/push/etc from the repository. My issue is with the command line tools & with the git tool integrations into PyCharm (my IDE).
I have my RSA keys in my $HOME/.ssh/ folder and a config file in $HOME/.ssh/config that has not changed...but now everytime I attempt to do a "git fetch" command from CMD/Powershell/Git Bash I get prompted for a password. This password prompt is showing up because it is NOT reading my SSH config file and it is NOT using my RSA key!!!!
I know this is the case because I can "fix" the issue in Git Bash by executing the following commands:
eval $(ssh-agent -s)
ssh-add C:/Users/MyUsername/.ssh/id_rsa
After executing those commands, everything works perfectly in Git Bash.
I have spent HOURS googling this issue and restarrting my SSH services, rebooting my computer, resintalling my IDE, and even attempting to do a system restore back to last week....NONE of them fix the issue.
WHY do I need to add my ssh keys to Git Bash everytime I open it? It seems like it is not reading the keys/config file from the default $HOME/.ssh directory. How do I fix this? What is going on? I'm about ready to throw this computer out the window!!!
Restarting Software - Nothing
Rebooting Computer - Nothing
Copying $HOME/.ssh/config to multiple directories as suggested by google search results - Nothing
Using Github Desktop - WORKS, but I want the CLI tools / integrated Git flow in PyCharm to work!
Using Git Bash with "eval $(ssh-agent -s); ssh-add" workaround - WORKS but very cumbersome. Why doesn't it remember the keys session to session? Why do I need to execute every time?
Hacky solution:
I used ssh -Tvvv git#gitlab both before and after executing the "eval $(ssh-agent -s); ssh-add " workaround and loaded them into Beyondcompare and noticed that the tool was trying to grab keys from C:\SPB_Data directory in the 'before' (I have no idea what this directory is) and C:\Users\MyUsername 'after':
debug1: Next authentication method: publickey
debug1: Trying private key: /c/SPB_Data/.ssh/id_rsa
debug3: no such identity: /c/SPB_Data/.ssh/id_rsa: No such file or directory
So I simply copied all the files from C:\Users\Myusername.ssh into C:\SPB_Data.ssh and then everything worked.
The root-cause of this issues seems to be the installation of Allegro / Cadence software which OVERWRITES the $HOME environment variable and causes OpenSSH to read from that folder instead of the Windows home folder.

IntelliJ IDEA git Permission denied (publickey)

I got a strange problem with using git on IntelliJ IDEA on Windows 10.
If I want to access the remote repo on GitLab, I always get
Permission denied (publickey).
Everything I found here or via Google didn't solve the problem.
I tried:
Setting the ssh executable to Native
Converting my public key from Putty to ssh-keygen style
Removing known_hosts
I also tried to access the repo with Git Bash, it works fine like that.
Another interesting fact is that after removing known_hosts, I got "Host key verification failed". I had to use Git Bash once to recreate the known_hosts entry, after that I got the Permission denied error again. Somehow I don't get asked for any user input.
I faced this problem while connecting bitbucket cloud from my Intellij 2019.2 , which thankfully got solved with the following steps. Please note that these steps are to be carried out after you successfully generate and add ssh-public key to your bitbucket/github/gitlab profile.
Open Git-SCM ssh_config file present in Git-SCM installation directory.It's default location in Windows (for 64 bit) is in C:\Program Files\Git\etc\ssh\
Add the following lines into ssh_config
Host *your-gitlab-or-github-or-bitbucket-hostname*
IdentityFile *your-ssh-rsa-privatekey-file-with-absolute-path*
for e.g
Host bitbucket.org
IdentityFile C:/Users/Sahil/.ssh/id_rsa
Source:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/360004124959-IntelliJ-2019-1-3-Can-t-access-git-using-SSH-keys
Update IDEA 2021.2.3
The bug in Sahil's answer has been fixed and Christian's solution is not needed with the correct entry in your ssh config file for the most common case of one key for one or more hosts. Additional options for complex configurations, such as multiple keys to the same or multiple hosts, can be found in Maddes comprehensive answer on superuser.
ANY inconsistency between ssh-agent and ssh-add leads to a situation where some things work and some don't.
For example, I had the Windows OpenSSH agent running but my path pointed first to the Git for Windows ssh-add. Many such failures are possible given the many ssh implementations out there, so know that you know where things are running from.
To get ssh working in IDEA...
Git for Windows
Install Git for Windows. I put it in C:\Git since, as a standard user without an elevated install, I couldn't write to C:\Program Files.
In Control Panel | User Accounts | Change my environment variables add the Git usr\bin folder to the path after the cmd folder entry already there (e.g. C:\Git\usr\bin for my installation).
Unset environment variable HOME -- it still breaks ssh in this version of IDEA.
In a Windows cmd.exe console, run start-ssh-agent.cmd to start the agent
In IDEA in Settings | SSH Configurations | Authentication type: set it to Key pair OpenSSH or PuTTY and test your connection. Then, make a small change and test Commit and push....
Windows OpenSSH
In Control Panel | User Accounts | Change my environment variables add C:\Windows\System32\OpenSSH to your path. Make sure no other ssh implementation is ahead of this in the path!
Start the OpenSSH agent in Task Manager | Services (or any number of other ways)
Set your IDEA SSH Configuration as #5 above
Keep in mind that, on Windows, ssh in IDEA uses the environment available in a standard Windows command-line console (cmd.exe). If git operations work there, then with the above steps in place, they'll work in IntelliJ.
It has been really long since OP but here is my solution on an execution basis:
You need to open a prompt and set the ENVVAR GIT_SSH_COMMAND.
You need to open IntelliJ from that same prompt.
Example:
> set GIT_SSH_COMMAND=ssh -i C:\\path\\to\\not\\default\\key
> idea
Also the path to not-default-key should use ~ instead of %userprofile% or paths unix-like using /.
I was having this same issue, and while it did have to do with the public key, my issue was concerned with WSL2/Linux and windows .ssh folders. My keys were in my WSL2/linux folder system, but intelliJ was looking in my windows folder system.
I copied my rsa keys from WSL2 to windows, and it worked automatically. In fact, I attempted to have it fail again by removing the keys from the Windows folders, but intelliJ must have it's own keylocker solution, because even without the keys in the Windows .ssh folder intelliJ continued to work.
For a screen capture explaining it you can see it here https://vimeo.com/558267383/74d55415c4
If you're using wsl2 in Clion like me, just add
Host github.com
IdentityFile /home/yieatn/.ssh/github
to /home/user/.ssh/config (create if it doesn't exit). You don't even have to restart IDE.
Adding to Cristian Torres's answer:
For all of you folks struggling with a similar problem on Mac OSX:
In IntelliJ, PyCharm, etc. click Tools -> Create Command-line Launcher...
Open your terminal and execute:
$ export GIT_SSH_COMMAND="ssh -i ~/.ssh/your-custom-private-key"
$ idea
For PyCharm the executable name is charm or /usr/local/bin/charm
Goland: goland or /usr/local/bin/goland
WebStorm: webstorm or /usr/local/bin/webstorm

SVN checkout mac terminal

I have some issues to download a directory though mac's terminal.
On Windows:
svn+ssh://netimage#xxxxxx.dk/home/netimage/svn/xxxxx.dk2
I've tried it though mac terminal via. this without luck.
svn co http://xxxxxx/home/netimage/svn xxxxxx --username netimage
also tried
svn co http://xxxxxx/home/netimage/svn/xxxxx.dk2 --username netimage
My password keyphrase is in "ssh add -K mypasswordkey.ppk"
What to do?
You are trying to use a Putty private key with Openssh. This won't work.
Solution: use one of the Putty programs (Puttygen?) to export your key into Openssh private key format. Then use that on your Mac.
You need to use svn+ssh:// and not http:// unless you also happen to be running Apache httpd on your server and configured it to serve Subversion.
What exactly is the issue when you try svn+ssh:// on your Mac? What error are you getting? Are you getting any error. The error message will help us figure out what the issue could be.
Most likely, you don't have your ssh keys setup correctly.
On the Mac's command line terminal, run the program 'ssh-keygen`. This will generate the public/private keys you need.
Once you do that, you need to go to your Mac's $HOME/.ssh directory and look for the file id_rsa.pub. This is your Mac's public key. Take that, and go to the system xxxxxx.dk and look in user netimage $HOME/.sshdirectory for anauthorized_keys` file. You will need your Mac's public key and add it to this file.
See if you can log in to your Subversion server via ssh without having to use your password. If you can do that, you have everything setup correctly. (Unless, of course, they've setup the server, so you can't log in with your account).
try this,
sudo svn --username user --password password co http://xxxx.xx/svn/projectname/

Source Tree for Windows doesn't seem to work with valid SSH key

I have created an ssh key pair using putty within Source Tree on Windows, and then added that to my repo client (I use Gitlab on a personal server).
This works fine from gitbash (cloning and pushing etc) and via SourceTree for OSX but after adding the .ppk key to pageant, which is actively running and seems to have loaded the key correctly, I cannot seem to clone via SourceTree. I get a "This is not a valid source Path/URL" when adding the repo path with details stating:
fatal: Could not read from remote repository. Please make sure you
have the correct access rights and repository exists.
If I add an existing repo that I have cloned using the same ssh key pair via git bash (by just drag dropping the folder into Source Tree for Windows) that seems to work up to a point - I can commit and see history etc. When I try to Push, however, it fails with much the same message (I've altered the repo path):
git -c diff.mnemonicprefix=false -c core.quotepath=false push -v
--tags origin master:master Pushing to git#MyServer.com:MyRepo.git
fatal: Could not read from remote repository. Please make sure you
have the correct access rights and the repository exists.
Completed with errors, see above.
As far as I can tell Pageant is up and running with the correct (well only) ssh key on my machine.
Any help is very welcomed.
Ok so this is a little embarrasing/confusing.
It would seem that I did not copy the correct public key onto my repo management web interface. The thing is, I copied the public key from git bash using the command:
clip < ~/.ssh/id_rsa.pub
But that seems to give me a different public key from what I actually get opening id_rsa.pub in a text editor...
Is that normal? Why is it different? Why does it work within gitbash and not in SourceTree (via pageant).
Anyway, copying the contents of my public key in directly from the file when opened in notepad got things to work with SourceTree and Pageant etc.

SVN+SSH and Sourceforge

I'm new to both Sourceforge and SVN (SilkSVN on Windows).
I managed to check out a project using
svn co --username=zeroth123 svn://zeroth123#svn.code.sf.net/p/stddecimal/code/trunk stddecimal-code
However, every time I try and use ssh (so I can check in for example) it fails with
> svn co --username=zeroth123 svn+ssh://zeroth123#svn.code.sf.net/p/stddecimal/code/trunk stddecimal-code
svn: E720087: Unable to connect to a repository at URL 'svn+ssh://zeroth123#svn.code.sf.net/p/stddecimal/code/trunk'
svn: E720087: Can't create tunnel: The parameter is incorrect.
I've set SVN_SSH to point to my fully qualified plink.exe and it makes no difference. I also tried changing it to junk.exe and didn't get anything different, so I don't think we're even looking at SVN_SSH, which exhausts all of the advice I've been able to find on the Sourceforge and other forums.
For the record I am the project administrator and therefore have write permissions (or at least think I do!)
Any ideas?
`%SVN_SSH% needs to be set correctly and an SSH key needs to be registered with Sourceforge.
Note that new Sourceforge projects are version 2.0 by default, while 99% of the Sourceforge documentation is for version 1.0 and appears outdated.
These instructions assume you have SVN and the PuTTY tools installed, and that you can successfully access your project using a non-secure protocol, eg the read-only svn checkout svn://USER#svn.code.sf.net/p/PROJECT/code/trunk PROJECT-code style command should work.
These instructions explain how to do the same with svn checkout svn+ssh://... which is needed for write access to Sourceforge.
Set %SVN_SSH% to the fully qualified path of your SSH client. E.g. setx SVN_SSH "C:/Program Files (x86)/PuTTY/plink.exe"
svn expects forward slashes or double back-slashes in the path
You may have to reopen a cmd window
Test by typing %SVN_SSH% at the prompt and confirm you get your ssh programs help screen (or whatever behaviour you expect from executing with no arguments)
(Optional?) Cache the server RSA key. Open PuTTY, login to svn.code.sf.net (or whatever the server of your project is). A prompt will appear asking if you if you want to cache the server RSA key - click Yes.
You might not need to do this, if not when you use SVN to connect ot your project for the first time you will be asked the same question. Type y.
However, I did this because I thought the interactive prompt could be part of the problem.
Create a public / private key and register the public key with Sourceforge.
On creating a key, more info herefor example.
If you use PuTTY, use PuTTYgen to create the key, and make sure the private key is loaded in pageant. Ironically Launchpad has excellent instructions.
The public key can be registered on Sourceforge by navigating to Home > Account > Services and clicking Edit SSH Keys for Shell/CVS.
Now a checkout using svn+ssh protocol should work!
I followed the instructions here and it worked. Its a quicker method that doesn't require uploading keys etc.
Download plink.exe from http://the.earth.li/~sgtatham/putty/latest/x86/plink.exe
Place the plink.exe in your windows installation directory (%windir%)
Open the following file using Notepad %APPDATA%\Subversion\config
Add or Replace the following line in the [tunnels] section (replace login and pwd with your sourceforge login and password)
ssh = c:\\windows\\plink.exe -batch -l <LOGIN> -pw <PWD>
(note the double backslash)
Save and close the file
For me the issue was that Tortoise was initially installed on the D drive. I uninstalled it and reinstalled it on C without changing the related settings. The solution was to copy the TortoiseSVN folder from C drive to its original location in D drive.
For anybody (like me) working with Tortoise SVN who has it working for Tortoise SVN but needs command line access for easier bulk analysis... and doesn't want to go through the faff of registering an SSH key.
Copy the value you are using in Tortoise - Settings - Network - SSH Client (mine has username, password arguments)
Edit the command line configs ssh line in %APPDATA%\Subversion\config as per the answer above to use the line you copied from Tortoise
That way, you can use the Tortoise Plink.exe with arguments for username and password.

Resources