Skip to content

Latest commit

 

History

History
60 lines (56 loc) · 2.85 KB

20221208.org

File metadata and controls

60 lines (56 loc) · 2.85 KB

Git for Windows protocol error when using Pageant

On Windows I use the SSH agent pageant to manage my keys for Git. This allows me to use the same agent process from Windows and MSYS2 Zsh sessions. But after I switched to pageant on a workstation that previously used the Git Credential Manager, Git commands that accessed a remote, failed:

C:\Users\Pieter\repos\my-repo> git pull
fatal: protocol error: bad line length character: logi
FATAL ERROR: Error reading from console: Error 109: The pipe has been ended.

The first hit by Google was this question on StackOverflow, Git Remote: Error: fatal: protocol error: bad line length character: Unab. Most answers pointed in the direction of pageant and plink, where plink replaces the ssh command as it can talk to pageant. Was pageant running? Were the keys loaded? Those all checked out so I focussed on plink.

To determine if plink was able to connect to the repo server, I executed the following command:

C:\Users\Pieter\repos\my-repo> plink -v -agent -P <port> <server>
Looking up host "<server>" for SSH connection
Connecting to <IP address> port <port>
We claim version: SSH-2.0-PuTTY_Release_0.78
Connected to <IP address>
Remote version: SSH-2.0-SSHBlackbox.10
Using SSH protocol version 2
Doing Diffie-Hellman group exchange
Doing Diffie-Hellman key exchange using 2048-bit modulus and hash SHA-256 (SHA-NI accelerated) with a server-supplied group
Host key fingerprint is:
ssh-rsa 2048 <fingerprint>
Initialised AES-256 SDCTR (AES-NI accelerated) outbound encryption
Initialised HMAC-SHA-256 (SHA-NI accelerated) outbound MAC algorithm
Initialised AES-256 SDCTR (AES-NI accelerated) inbound encryption
Initialised HMAC-SHA-256 (SHA-NI accelerated) inbound MAC algorithm
Pageant is running. Requesting keys.
Pageant has 1 SSH-2 keys
login as:

Note the last line, which asks me for my username. It starts with the same characters as the first line of the error message, logi. Another Google search brought me to this answer to the StackOverflow question mentioned before:

TL;DR: Do not omit username@ in your remote URLs when on Windows.

By default SSH uses your current username, but plink doesn’t do that. So when Git calls plink, plink will ask as which user it should connect.

Indeed, the .gitconfig for that repo defined origin without the username:

[remote "origin"]
	url = ssh://<server>:<port>/<repo-path>

Once I added the username to the repo address,

[remote "origin"]
	url = ssh://<username>@<server>:<port>/<repo-path>

the Git commands worked.