Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Remote-SSH Bug]: Adding new host breaks ssh config file when there are spaces in the host, with more detail #8320

Open
3 tasks done
seaofbits opened this issue Apr 4, 2023 · 5 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug ssh Issue in vscode-remote SSH
Milestone

Comments

@seaofbits
Copy link

Is there an existing issue for this bug?

  • I have searched the existing issues

Required Troubleshooting Steps

  • I have followed these troubleshooting steps
  • I have tried both values of the remote.SSH.useLocalServer setting

Connect Locally

It connects successfully

->

No response

Expected Behavior

Hi there!
This is infact an old issue #6197. I'am sorry that I did't get any notice about the reply until today, and the thread is closed now, and unfotrunatly the bug still exist. So I have to open a new issue.
It's just a simple bug, but I recognize that I didn't explain it clearly in the old issue. So I improved the details and paste again here. (If it's better to continue in the old thread, I can repose the detail again there.)

Steps To Reproduce

All in GIF:
1

Detailed Steps below:

  1. Prepare an example config file, which has quoted string with space.
Host "vm-ubuntu-2004"
  HostName 192.168.211.128
  User example
  Port 22

Host "CentOS 7.9 no GPU"
  HostName zone1.example.com
  User example
  Port 2224
  1. click left-buttom green-area, click Connect to Host..., click Add new host..., type any valid ssh string, such as ssh hello@microsoft.com -A.
    3

  2. You can see the broken ssh config how.
    4

Remote-SSH Log

Remote-SSH Log

[13:27:31.809] Log Level: 2
[13:27:31.824] VS Code version: 1.73.1
[13:27:31.825] Remote-SSH version: remote-ssh@0.96.0
[13:27:31.825] win32 x64
[13:31:17.492] Picking SSH host

Anything else?

No response

@seaofbits seaofbits added the ssh Issue in vscode-remote SSH label Apr 4, 2023
@roblourens roblourens added the bug Issue identified by VS Code Team member as probable bug label Apr 4, 2023
@roblourens roblourens added this to the Backlog milestone Apr 4, 2023
@roblourens roblourens assigned eleanorjboyd and unassigned roblourens Apr 4, 2023
@roblourens
Copy link
Member

roblourens commented Apr 4, 2023

Possibly an issue with the ssh-config library- not sure whether the quoting is supposed to happen on that end or whether we are supposed to do something

@seaofbits
Copy link
Author

I've checked the manual of the ssh_config:

The file contains keyword-argument pairs, one per line. Lines starting with ‘#’ and empty lines are interpreted as comments. Arguments may optionally be enclosed in double quotes (") in order to represent arguments containing spaces. Configuration options may be separated by whitespace or optional whitespace and exactly one ‘=’; the latter format is useful to avoid the need to quote whitespace when specifying configuration options using the ssh, scp, and sftp -o option.

The possible keywords and their meanings are as follows (note that keywords are case-insensitive and arguments are case-sensitive):

Host ...

So spaces in the argument of Host is valid in grammar. And it's useful too, I usually configure as below:

Host "CentOS 7.9 no GPU" ai
  HostName zone1.example.com
  User example
  Port 2224

This allows me to see a readable name in the green-block in the left of status bar, and I can use ssh ai to connect to my server conveniently.

@seaofbits
Copy link
Author

I don't know what's the implementaion of the Add new host... function. It seems (just seems in my opinion) easy to fix because we can just simply add some line on the top of the configuration file, and keep rest of the file original.

In fact, the bug just affect me when it occurs for the first time, it slightly breaks my ssh_config file. After that, I'am always editting ~/.ssh/ssh_config mahually.

@eleanorjboyd
Copy link
Member

Hi! To follow up the fix for me seems to be when using "add new ssh host" and typing in ssh "host name" for example, this is valid and should be saved in the ssh config as Host "host name". Currently, it is saved as Host host name which breaks it. Fix is just to the "add new ssh host" command to keep quotes when copying over.

@seaofbits
Copy link
Author

Hi! To follow up the fix for me seems to be when using "add new ssh host" and typing in ssh "host name" for example, this is valid and should be saved in the ssh config as Host "host name". Currently, it is saved as Host host name which breaks it. Fix is just to the "add new ssh host" command to keep quotes when copying over.

Yes, this is one aspect. Another aspect is, if you type ssh "host2 name", it will break ALL existing lines like Host "host name" in the ssh_config file.

In other words, we can have a test case:

  1. In "add new ssh host", type ssh "host name", it should be saved as Host "host name" in ssh_config.
  2. In "add new ssh host", type ssh "host name 2", it should be saved correctly too, and the previous Host "host name" is not broken.

@eleanorjboyd eleanorjboyd removed their assignment Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug ssh Issue in vscode-remote SSH
Projects
None yet
Development

No branches or pull requests

3 participants