GitExtensions - OpenSSH ignores ~/.ssh/config file - openssh

Using gitextensions I try to clone my remote repository which results in gitextensions running the following command
> C:\cygwin\bin\git.exe clone -v --recurse-submodules --progress "gitbox:/projects/testing.git" "C:/Users/craig/MyCode/Personal/testing"
which fails with
Permission denied (publickey).
However if I run the exact same command from a cygwin bash shell it succeeds. So in addition to a standard configuration I also have a ~/.ssh/config which sets up the 'gitbox' alias for ease of use.
My ~/.ssh/config file looks like this
# My GitBox -
Host gitbox
Hostname mydomain.com
User git
IdentityFile /home/craig/.ssh/craig#home
Port 2022 # i.e non-standard port
In GitExtensions I have the OpenSSH option checked, and I also have HOME set to where my cygwin installation is, and more specifically where the user account ie c:/cygwin/home/craig
My conclusion is that somehow the ~/.ssh/config file is not being read and utilised. Everything I can find indicates that an incorrect HOME directory in gitextensions would be the problem but I can't see what's up with my setup.
Thanks in advance
Craig

GitExtensions by default set HOME variable to "C:\Users\". You can change this in settings dialog.

Related

Offending RSA key in /u/.ssh/known_hosts during git clone on windows

I am trying to git clone a repository on my windows machine, with:
git clone -b <branch> ssh://<host>
I have already added the keys, and deleted the existing known_hosts file in C:\Users<username>.ssh
But the git clone fails with
###########################################################
# WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! #
###########################################################
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the DSA key sent by the remote host is
SHA256:<fingerprint>.
Please contact your system administrator.
Add correct host key in /u/.ssh/known_hosts to get rid of this message.
Offending RSA key in /u/.ssh/known_hosts:6
Where is this known_hosts (/u/.ssh/known_hosts) file? C:\Users<username>\.ssh does not have this file, I was expecting for it to get created in the git clone command.
The same command works fine on my ubuntu PC.
The mentioned path has an linux-ish look, which indicates you were probably running your command from git-bash.
The simplest way to fix your issue is to edit the mentioned file (/u/.ssh/known_hosts) from a git-bash shell.
Check your environment variable HOME: in a CMD, type set HOME.
If it is set to U:\ (translated, in a bash session, to /u/), that would explain why SSH is lookig for information (keys, config file, known_hosts file, ...) in U:\.ssh
Change your HOME environment variable (back to, for instance, %USERPROFILE%) to make sure SSH looks for keys where you expect it.

How to automatically use a specific SSH key when using Git through a JetBrains IDE (i.e. PyCharm) on Windows?

I would like to use a specific SSH key when using Git through PyCharm on Windows.
Things I have tried:
Tried configuring SSH by adjusting the ~/.ssh/config (and permissions) as mentioned in these answers:
https://stackoverflow.com/a/31044770/8488985
https://stackoverflow.com/a/11251797
https://superuser.com/a/232406 (See for comments about permissions)
This enabled Git when used in the Git Bash command line, however, it did not work when using the IDE.
Tried adding the SSH key to the ssh-agent as mentioned in here:
https://stackoverflow.com/a/4565746
Again, this enabled Git when used in the Git Bash command line, however, it did not work when using the IDE.
What else can I do?
Apparantly JetBrains IDEs (like PyCharm) use the Windows commandline to interact with git.
See here
So the first step is to startup the Windows Command Prompt and check if you can use Git with a specific SSH key that way.
In my case this was not possible, even though I had configured the config file located at ~/.ssh/config (when accessed through Git Windows) or C:\Users\<Me>\.ssh\config.
This is why the SO posts mentioned in my question did not solve my problem.
The second step is to figure out which config file instead is used by Git when accessed through the Windows Command Prompt.
This provided me the clue that Git on Windows can use an internal ssh config file called ssh_config (instead of config) and located near the git.exe (instead of in a subdir of your homedir).
I found Git's location using where git which indicated C:\Program Files\Git-2.16.1\cmd\git.exe.
So the config I was looking for was located at C:\Program Files\Git-2.16.1\etc\ssh\ssh_config.
The third step is adjusting that ssh_config file similar to the config file.
For me this looked like this:
Host <some-name>
HostName gitlab.com
IdentityFile C:\Users\<Me>\.ssh\<my-non-default-key>
# Prevents usage of the default IdentityFile
# See: https://stackoverflow.com/a/11251797
IdentitiesOnly yes
# Prevents warning when pulling from Gitlab.
# See: https://stackoverflow.com/a/67556915
UpdateHostKeys no
The fourth and last step is to change the remote in the Git repository such that it uses the name <some-name> specified in the ssh_config file.
Get the original remote first using git remote -v.
This gives something like this:
git#gitlab.com:some/subdirs/to/the/repository.git
Now swap out the gitlab.com part for <some-name> specified in the ssh_config file, like this:
git remote set-url origin git#<some-name>:some/subdirs/to/the/repository.git
Summary:
When using a JetBrains IDE like PyCharm it uses Git over the Windows Command Prompt
Find out the location of Git in the Windows Command Prompt
Adjust the ssh_config file located at this Git location
Set the remote url of the repository such that it uses the host name specified in the ssh_config file

Git prompting for password when using SSH, even when SSH keys are present (but running as admin works). What is the issue?

In a corporate environment running Windows I have the following issue:
Using git via SSH via
git clone git#server:repo.git
I am prompted for a password:
git clone git#server:repo.git
Cloning into 'repo'...
git#server's password:
The SSH Key is not found, although my SSH key resides in C:\Users\[USERNAME]\.ssh.
However, running the command shell (CMD) as administrator, everything works just fine.
What is the issue and how can it be fixed?
(Note: I am answering my own question since the issue wasted hours of my time and I did not see it in other issues having similar "access denied" symptoms).
Getting "access denied" or haven SSH keys not recognised may have a variety of reasons, see also
https://serverfault.com/questions/194567/how-do-i-tell-git-for-windows-where-to-find-my-private-rsa-key
The issue above - where git works when run as local admin, but not as user - is possibly related to a specific setup in a corporate environment. In my case the machine had a folder C:\Users\[USERNAME] but also a profile on a network mounted drive (say N). The .ssh folder with my key resided in C:\Users\[USERNAME] but git was looking in N:
Running as (Local) Administrator on the Machine changed the behaviour and used the profile from C:\Users\[USERNAME].
To find your home folder:
open Git Bash on Windows
type cd ~;pwd
The issue is ultimately related to different settings of the environment variables HOMEDRIVE, HOMESHARE or USERPROFILE, see also Git bash home directory different from Git extension than Git Bash

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

Unable to clone git repository from siteground

I'm trying to set up MS WebMatrix to use a Git repository from my siteground hosting account. I created the repository using their cpanel plugin and it tells me that I can clone it using this command
git clone ssh://username#sm3.siteground.biz:18765/home/username/public_html/
I replaced username of course and I created an rsa key using ssh-keygen. In the Webmatrix GUI it just opens a window saying "Clone is in progress" but it doesn't to anything.
And when I run that command in PowerShell, this is the output:
Cloning into 'public_html'...
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Any help is highly appreciated!
EDIT:
I haven't used github before but I'm pretty sure I'm not connecting to it. The repository is on siteground's server I think. Anyway, I couldn't figure it out in PowerShell so now I'm using putty to load the appropriate key and connect using an external git tool (source tree) that doesn't use the same ssh client as PowerShell. That is the solution that's working for me now.
I'll leave this question open as maybe someone comes around and can help with how to set this up using PowerShell.
The missing piece to the Siteground guide is:
Create a blank file in ~/.ssh/ or C:\Users\username\.ssh on your computer. It does not matter what you name it. I named it siteground_dsa. You could also name it id_dsa_siteground.
Copy the private ssh key that you get from siteground.com and paste the whole of it in the this newly created file.
Open Git Bash locally on your computer and run the following command
$ eval ssh-agent -s
Then run the following. Remember to use the filename that you gave it.
$ ssh-add ~/.ssh/siteground_dsa
Now you need to enter the passphrase for the ssh key. You will have defined it when creating the ssh key.
Now you should be logged in and you can run git clone the directory of your wish.
git clone ssh://username#ams14.siteground.eu:18765/home/username/public_html/
To permanently add the SSH key extend ~/.ssh/config with the following and updating server_name and username.
Host server_name
User username
Port 18765
IdentityFile ~/.ssh/siteground_dsa
keep in mind that for Windows operators, you should write eval $(ssh-agent)
eval $(ssh-agent)
chmod 600 file_name
ssh-add C:\Users\username\.ssh\siteground
Then you can easily clone your file into your local server following inserting your passphrase of the SSH key.
GitHub isn't able to authenticate you. Probably your key isn't associated with your GitHub account.
Take a look to GitHub's recommended method

Resources