VS Code Remote-SSH Causing Git Push Failure

This page is machine-translated and may contain errors. Read the Chinese original

Problem Description

Today, while using Git Push in VS Code, the following error suddenly appeared:

1
2
3
4
5
6
> git push origin master:master
/Users/xxx/.ssh/config line 6: invalid time value.
/Users/xxx/.ssh/config line 7: integer value invalid.
/Users/xxx/.ssh/config line 8: unsupported option
/Users/xxx/.ssh/config: terminating, 3 bad configuration options
fatal: Could not read from remote repository.

Cause Analysis

After investigation, the issue was traced to the ~/.ssh/config configuration file.

Previously, when I used the Add New SSH Host feature built into the VS Code Remote-SSH plugin to add a remote host, the plugin automatically rewrote the SSH configuration file, causing the spaces between some configuration items and their end-of-line comments to be lost.

The error is as follows:

The original configuration looked like this:

1
2
3
4
Host *
ServerAliveInterval 60 # 每 60s 发一次心跳
ServerAliveCountMax 3 # 连续 3 次无响应才断开
AddKeysToAgent yes # 自动把密钥加入 ssh-agent

After using the SSH plugin to add a host, the plugin automatically rewrote the .ssh/config file, and after processing it became the following format:

1
2
3
4
Host *
ServerAliveInterval 60# 每 60s 发一次心跳
ServerAliveCountMax 3# 连续 3 次无响应才断开
AddKeysToAgent yes# 自动把密钥加入 ssh-agent

Because the parameter values are directly connected to #, OpenSSH cannot correctly parse the configuration items, which causes SSH initialization to fail, thereby affecting Git Push, and the SSH plugin also becomes unusable.