Cannot access git repo using Git for Windows or TortoiseGit - windows

I do some development work for a friend, who runs his own Linux git server. Everything worked until he decided to harden his server. He decided 1024-bit keys weren't good enough, so I sent him a new 4096-bit public key.
Now I can no longer access the repository from Windows.
The repository url is ssh://git#1.2.3.4:2000/home/git/code.git (IP address changed to protect the innocent). Note that ssh runs on port 2000.
Trying to clone the repo from TortoiseGit gives "Server refused our key" in the git window, and "No supported authentication methods available (server sent: publickey, gssapi-keyex,gssapi-with-mic)" in an error dialog.
Trying from Git for Windows bash gives "fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists."
However, I can happily clone the same repo from a Linux VM running on the same machine, using the same key pair.
I have updated both Git for Windows and TortoiseGit with the latest version today.
[Later] I can actually log into the server from Putty and from Git bash:
$ ssh-agent bash
MINGW64 /e/folder
$ ssh-add rsa4096
Identity added: rsa4096 (rsa4096)
MINGW64 /e/folder
$ ssh -p 2000 git#1.2.3.4
Last login: Fri Jan 8 17:11:32 2021 from my.local.machine
(Ip addresses and machine names changed)
I can also login using "C:\Program Files\TortoiseGit\bin\TortoiseGitPlink.exe" -P 2000 (the GIT_SSH variable is set to C:\Program Files\TortoiseGit\bin\TortoiseGitPlink.exe)
Not sure what to try now - help!

Related

Trouble connecting to Git server (bitbucket.org) via Win 10 Git Bash

I had to restart my machine but things were working before hand. I was using Git Bash with SSH and hoses on Win 10 to connect to BitBucket which was fine.
I then had to also connect with Git Bash (another instance) to GitHub. This required Putty and Pagent to get setup.
No I try to connect to BitBucket and get this:
git pull origin mybranch
FATAL ERROR: No supported authentication methods available (server sent: publickey)
fatal: Could not read from remote repository.
Is there a simple way to have both working in different shells?
I tried to do a plink.exe to bitbucket.org but that made things worse.
Is there a simple way to have both working in different shells?
Yes. You can use any single method (from both) for connecting to HG|BB. Just select preferred way (ssh + ssh-agent OR pageant) and perform needed steps according to relevant docs

Problem cloning bare repository from windows 10 git server to windows 7 client: does not appear to be a git repository

I created a bare repository on windows 10 workstation which is attached to company private network
cd c:\users\remoteusername\gitserver
mkdir myrepo.git
cd myrepo.git
git init --bare --shared=group
Thereafter I setup an ssh server on this windows server using Win32_OpenSSH
On my windows 7 client, I first create a pair of public/private ssh keys from git shell and added it to ssh-agent:
cd c:\users\localusername\.ssh\
ssh-keygen.exe -t ed25519
eval `ssh-agent -s`
ssh-add.exe id_ed25519
This generated public/private key pair id_ed25519.pub and id_ed25519 on my windows 7 client machine.
Then I copied the contents from public key id_ed25519.pub to file c:\users\remoteusername.ssh\authorized_keys on windows 10 server which hosts my bare git repository.
I restart ssh daemon on the windows 10 server
net stop sshd
net start sshd
hello
Next, on my windows 7 client, I connect to my companies private network through VPN. I first check if I could connect from my Windows 7 client to Windows 10 machine via ssh using my remoteusername:
ssh remoteusername#myorg.com
I was successfully able to connect using my remoteusername. However, if I used 'git' as user name with ssh, I can't connect:
ssh git#myorg.com
git#myorg.com's password:
Permission denied, please try again.
Next I try to clone my remote repository on my local machine but it fails:
git clone ssh://remoteusername#myorg.com/C:/Users/remoteusername/gitserver/myrepo.git testrepo
Cloning into 'testrepo'...
remoteusername#myorg.com's password: 'git-upload-pack' is not recognized as an internal or external command,
operable program or batch file.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
To resolve error with unrecognized command 'git-upload-pack', on my Windows 10 server, I added paths of git sub-folders with binaries to my environment PATH variable:
C:\Users\remoteusername\AppData\Local\Programs\Git\bin
C:\Users\remoteusername\AppData\Local\Programs\Git\mingw64\bin
I again try to clone my remote repository on my local machine but it fails with a different error:
git clone ssh://remoteusername#myorg.com:/C/Users/remoteusername/gitserver/myrepo.git testrepo
Cloning into 'testrepo'...
remoteusername#myorg.com's password:
fatal: ''/C/Users/remoteusername/gitserver/myrepo.git'' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Anyone knows what is that I am missing and how to resolve this ?

Using VS Code with native Windows OpenSSH client

I'm trying to pass from Putty/Pagent/plink to Windows OpenSSH native client.
I already managed to do this in TortoiseGit, but with the main problem with VSCode seem to be I can't set which ssh agent to use.
I enabled the OpenSSH agent service on Windows to start automatically and added my open ssh key with ssh-add.
Every time i try to push from VSCode all i got is an error message with
Git: FATAL ERROR: Disconnected: No supported authentication methods available (server sent: public key)
When trying to push from terminal I got also
Please make sure you have the correct access rights and the repository exists.
As already said, with TortoiseGit I have no problem at all, and the only differences are that in TortoiseGit I set the ssh-agent.
you might need to confirm your System environment variable GIT_SSH points to the ssh within Git: C:\Program Files\Git\usr\bin\ssh.exe
You may need to update your Windows OpenSSH. If you run ssh -V from a PowerShell window and see OpenSSH_for_Windows_7.7p1, this is probably the case. The instructions for upgrading are available in the Install Win32 OpenSSH Wiki.
General
VS Code uses the Windows version of OpenSSH.
The config file that you change in VS Code is located in /Users/<username>/.ssh/config
The default location/name of a key is at /Users/<username>/.ssh/id_rsa.
Example
Local: Windows 10 machine with VS Code and the very awesome Remote - SSH extension installed
Remote: Ubuntu, where I use git for development and need my private key available
Since the remote is shared, I want to use SSH agent forwarding and keep my private key(s) on my local machine
Config file:
Host mybox
HostName actual.ip.or.name.of.mybox.com
User myusername
IdentityFile ~/.ssh/id_rsa
ForwardAgent yes
PowerShell Commands (Run as Administrator)
Start-Service ssh-agent
ssh-add C:\Users\<username>\.ssh\id_rsa # private key to add
ssh-add -L # list keys added
Set-Service ssh-agent -StartupType Automatic # optional

Unable to git clone from one folder to another in windows

I have a created a bare repository in C drive and I'm trying to clone the same in D drive by issuing the below command (in windows machine)
git clone Username#Ip_address_of_my_machine:C:/path_to_the_git_repo
but I'm unable clone it as it comes up with the error
"Cloning into 'git_repos'...
ssh: connect to host 192.168.0.5 port 22: Connection refused
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists."
I have installed CopSSH and set up id_rsa.pub keys and authorized key.
as mentioned in on github.
Is this problem is because of the dynamic IP address of my PC which is getting from the service provider? or what else is missing here?
I have tried the same in my office PC with same settings and installation, it works well with above git clone command, The difference is office PC has static IP but #home it is dynamic IP
Skip the ssh part as this is on the same machine. So from where you want the project to be in the D drive:
git clone C:/path_to_the_git_repo

Setup git over ssh in Rubymine on Windows

I found a lot of threads about how to setup git over ssh with msysgit and putty/plink, but rubymine seems to use its own git and ssh implementation (see error message below).
Currently I have putty, msysgit, TortoiseGit and rubymine installed. My repository has two remotes:
[remote "origin"]
url = ssh://mygituser#255.255.255.255:1234/path/to/repo.git
[remote "origin_putty"]
url = putty-alias:path/to/repo.git
puttykeyfile = path/to/my/putty/keyfile.ppk
In putty the connection "putty-alias" is defined with the same user, host and port used in origin and also sets the ssh key again (might not be necessary). Using TortoiseGit to push to origin_putty works fine since it loads the putty ssh key and prompts for my passphrase. However, when I'm trying to use origin from rubymine it prompts for the password of mygituser since there is no keyfile defined.
I already tried the following solutions
Setting GIT_SSH to plink, running pageant and loading the key there (no change)
using the puttykeyfile line in the definition of origin (no change)
using origin_putty from rubymine (does not resolve putty-alias)
The reason I think rubymine uses its own ssh implementation is the error message I get on an unsuccessful authentication:
SSH: authentication methods: [publickey, keyboard-interactive, password] last successful method:
java.io.IOException: Authentication failed:
at org.jetbrains.git4idea.ssh.SSHMain.authenticate(SSHMain.java:280)
at org.jetbrains.git4idea.ssh.SSHMain.start(SSHMain.java:155)
at org.jetbrains.git4idea.ssh.SSHMain.main(SSHMain.java:135)
fatal: The remote end hung up unexpectedly
You're right: by default RubyMine uses trilead-ssh2 Java library, and is not aware about Putty settings.
You may switch to using the native SSH in the Settings | Version Control | Git | SSH Executable | Native
But note, that it doesn't work well with passphrases, so if your private key is passphrase protected, you have to use pageant or similar software.

Resources