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

using localusername vs remoteusername #2102

Closed
JamesNewton opened this issue Dec 27, 2019 · 18 comments
Closed

using localusername vs remoteusername #2102

JamesNewton opened this issue Dec 27, 2019 · 18 comments
Assignees
Labels
*duplicate Issue identified as a duplicate of another issue(s) ssh Issue in vscode-remote SSH

Comments

@JamesNewton
Copy link

JamesNewton commented Dec 27, 2019

Issue Type: Bug

For some reason, it's apparently calling the git ssh client without specifying the user name I've entered in the config file. It's using the Windows user name (which I've replaced here with "localusername") instead of "remoteusername" as specified on the .ssh config file:

Host 1.2.3.4
    User remoteusername
    HostName 1.2.3.4
    IdentityFile ~/.ssh/remotekey

Here is the output:
[22:08:14.043] remote-ssh@0.47.2
[22:08:14.043] win32 x64
[22:08:14.047] SSH Resolver called for "ssh-remote+1.2.3.4", attempt 1
[22:08:14.047] SSH Resolver called for host: 1.2.3.4
[22:08:14.047] Setting up SSH remote "1.2.3.4"
[22:08:14.085] Using commit id "asdfas" and quality "stable" for server
[22:08:14.087] Testing ssh with ssh -V
[22:08:14.091] Got error from ssh: spawn ssh ENOENT
[22:08:14.091] Testing ssh with C:\Windows\System32\OpenSSH\ssh.exe -V
[22:08:14.093] Got error from ssh: spawn C:\Windows\System32\OpenSSH\ssh.exe ENOENT
[22:08:14.093] Testing ssh with C:\Program Files\Git\usr\bin\ssh.exe -V
[22:08:18.674] ssh exited with code: 0
[22:08:18.674] Got stderr from ssh: OpenSSH_7.6p1, OpenSSL 1.0.2n 7 Dec 2017
[22:08:18.682] Running script with connection command: "C:\Program Files\Git\usr\bin\ssh.exe" -T -D 60247 1.2.3.4 bash
[22:08:18.703] Install and start server if needed
[22:08:18.706] Terminal shell path: C:\Windows\System32\cmd.exe
[22:08:19.015] >
[22:08:19.015] Got some output, clearing connection timeout
[22:08:19.649] > localusername@1.2.3.4: Permission denied (publickey).

Notice it doesn't specify the remote username on the command for git ssh, and the error message indicates the localusername was used instead.

I am able to connect to the remote server via PuTTY using a key file and the correct remote user name.

Extension version: 0.47.2
VS Code version: Code 1.38.1 (b37e54c98e1a74ba89e03073e5a3761284e3ffb0, 2019-09-11T13:35:15.005Z)
OS version: Windows_NT x64 6.1.7601

System Info
Item Value
CPUs Intel(R) Core(TM) i7-2630QM CPU @ 2.00GHz (8 x 1995)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
oop_rasterization: unavailable_off
protected_video_decode: unavailable_off
rasterization: unavailable_off
skia_deferred_display_list: disabled_off
skia_renderer: disabled_off
surface_synchronization: enabled_on
video_decode: enabled
viz_display_compositor: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 7.98GB (1.69GB free)
Process Argv
Screen Reader no
VM 0%
@aeschli aeschli added the ssh Issue in vscode-remote SSH label Dec 30, 2019
@roblourens
Copy link
Member

I think you need a Host that doesn't match the HostName, if you change it to some other name does that work?

@roblourens roblourens added the info-needed Issue requires more information from poster label Jan 2, 2020
@push7joshi
Copy link

push7joshi commented Jan 3, 2020

I am running into same issue. @roblourens I tried using a host that does not match the hostname, that does not seem to work. From the vs code output ssh -T -D 62050 -o ConnectTimeout=15 <remotehost> bash
The ssh command is missing the remote user name specified in ssh config.

@roblourens
Copy link
Member

It won't be in that command, ssh will read it from the config file. Please make sure that it is actually seeing the correct ssh config file.

@JamesNewton
Copy link
Author

JamesNewton commented Jan 4, 2020

If I change the host to anything other than the remote servers ip address, then it fails to resolve it: " ssh: Could not resolve hostname hostname: Name or service not known"

[21:06:37.661] remote-ssh@0.47.2
[21:06:37.661] win32 x64
[21:06:37.666] SSH Resolver called for "ssh-remote+asdfasdfsdf", attempt 1
[21:06:37.666] SSH Resolver called for host: HostName
[21:06:37.666] Setting up SSH remote "HostName"
[21:06:37.736] Using commit id "aasdfasdfsdfdf" and quality "stable" for server
[21:06:37.738] Testing ssh with ssh -V
[21:06:37.743] Got error from ssh: spawn ssh ENOENT
[21:06:37.743] Testing ssh with C:\Windows\System32\OpenSSH\ssh.exe -V
[21:06:37.745] Got error from ssh: spawn C:\Windows\System32\OpenSSH\ssh.exe ENOENT
[21:06:37.746] Testing ssh with C:\Program Files\Git\usr\bin\ssh.exe -V
[21:06:42.332] ssh exited with code: 0
[21:06:42.332] Got stderr from ssh: OpenSSH_7.6p1, OpenSSL 1.0.2n 7 Dec 2017
[21:06:42.341] Running script with connection command: "C:\Program Files\Git\usr\bin\ssh.exe" -T -D 52368 HostName bash
[21:06:42.344] Install and start server if needed
[21:06:42.349] Terminal shell path: C:\Windows\System32\cmd.exe
[21:06:42.653] >
[21:06:42.653] Got some output, clearing connection timeout
[21:06:47.651] > ssh: Could not resolve hostname hostname: Name or service not known

The process tried to write to a nonexistent pipe.

[21:06:47.973] "install" terminal command done
[21:06:47.973] Install terminal quit with output: The process tried to write to a nonexistent pipe.
[21:06:47.973] Received install output: The process tried to write to a nonexistent pipe.
[21:06:47.974] Resolver error: The process tried to write to a nonexistent pipe
[21:06:47.976] TELEMETRY: {"eventName":"resolver","properties":{"outcome":"failure","reason":"OfflineError","askedPw":"0","askedPassphrase":"0","asked2fa":"0","askedHostKey":"0","gotUnrecognizedPrompt":"0","remoteInConfigFile":"1"},"measures":{"resolveAttempts":1,"retries":1}}
[21:06:47.977] ------

@roblourens
Copy link
Member

Then it's not finding your config file. What's the path to the config file? This needs to work from an external terminal - <path to ssh> <hostname>

@push7joshi
Copy link

push7joshi commented Jan 6, 2020

It seems like my ssh config file had something incorrect with so many servers in it. I moved this remote server to the top and that worked. Thank you for your response.

@JamesNewton
Copy link
Author

@roblourens I don't understand why you would think the config file can't be found... how would the config show up in the Remote Explorer sidebar if the config file wasn't found? The config file is

C:\Users\LocalUser\.ssh\config

(replacing my actual user name with "LocalUser for privacy) and it currently contains

# Read more about SSH config files: https://linux.die.net/man/5/ssh_config
Host ChatServer
    User remoteuser
    HostName 1.2.3.4
    IdentityFile C:\\Users\\HostName\\.ssh\\IdentityFile

actual data replaced with anon equivalence for privacy. E.g. the IP address is not actually 1.2.3.4 obviously, and the Host is just a name I made up, not actually "ChatServer" (previously, I called the Host "HostName" but now I'm replacing it with "ChatServer" so there is no confusion with the HostName parameter in the config file. My username on that remote system is not actually "remoteuser" but IS my valid username. In my prior entry here, the line:
[21:06:42.341] Running script with connection command: "C:\Program Files\Git\usr\bin\ssh.exe" -T -D 52368 HostName bash
would be:
[21:06:42.341] Running script with connection command: "C:\Program Files\Git\usr\bin\ssh.exe" -T -D 52368 ChatServer bash

I don't understand this at all:

This needs to work from an external terminal -

What do you mean by "external terminal"? Command prompt? Unix terminal window? Are you talking about the path to the ssh program?

If I do
"C:\Program Files\Git\usr\bin\ssh.exe" -T -D 52368 1.2.3.4 bash
it does connect (it then fails because the identity file isn't specified.) The point is that Remote Explorer is passing "DexChat" instead of "1.2.3.4" despite the fact that the HostName specified in the config file for DexChat is 1.2.3.4. Does that make sense? The bug is that you are passing the Host, not the HostName as the address to connect to.

I don't know how to edit the command line options for Git ssh and I have no idea what the -T and -D options are doing, but if I open a command prompt and from C:\Users\LocalUser> enter:
"C:\Program Files\Git\usr\bin\ssh.exe" -i .ssh\IdentityFile remoteuser@1.2.3.4
and then correctly respond to the request for the passphrase, I am connected to the remote server.

@roblourens
Copy link
Member

how would the config show up in the Remote Explorer sidebar if the config file wasn't found

VS Code looks for the ssh config file in that location but the ssh program should also be looking for it there. VS Code is finding it but ssh.exe is doing something weird. In your example,

"C:\Program Files\Git\usr\bin\ssh.exe" ChatServer should work. If not, you can add the verbose flag like -vvv and it should print where it is looking for an ssh config file, and that should tell us why it's not finding it.

@JamesNewton
Copy link
Author

"C:\Program Files\Git\usr\bin\ssh.exe" ChatServer should work.

Are you sure that's how Git ssh works? If you want it to use a config file, I believe you have to add the -F flag. If you specify a parameter without a flag, it's expected to be a fqdn or ip address to the server.

-vvv is certainly not an option for the Git ssh program.

Here is the help:

"C:\Program Files\Git\usr\bin\ssh.exe"  -v
usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
           [-D [bind_address:]port] [-E log_file] [-e escape_char]
           [-F configfile] [-I pkcs11] [-i identity_file]
           [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec]
           [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address]
           [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]]
           [user@]hostname [command]

Is the issue that remote explorer does not support Git ssh? Is there another ssh program you know works under Windows?

@roblourens
Copy link
Member

No, it should read the ssh config files from their default locations without using the -F flag. And that is not a complete listing of all flags. Just try it. You should see output like this

PS C:\Users\roblou> & 'C:\Program Files\Git\usr\bin\ssh.exe' robfast -vvv
OpenSSH_7.9p1, OpenSSL 1.1.1a  20 Nov 2018
debug1: Reading configuration data /c/Users/roblou/.ssh/config
debug1: /c/Users/roblou/.ssh/config line 1: Applying options for robfast
debug1: /c/Users/roblou/.ssh/config line 50: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolve_canonicalize: hostname 123.123.123.123 is address

@JamesNewton
Copy link
Author

"C:\Program Files\Git\usr\bin\ssh.exe" ChatServer
ssh: Could not resolve hostname chatserver: Name or service not known

@roblourens
Copy link
Member

Thanks, now can you try it with the verbose flag so it will log where it is looking for a config file?

@JamesNewton
Copy link
Author

"C:\Program Files\Git\usr\bin\ssh.exe" -vvv -F .ssh\config ChatServer
OpenSSH_7.6p1, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolving "ChatServer" port 22
ssh: Could not resolve hostname ChatServer: Name or service not known

So in that case, it's looking in a place that doesn't exist for the config.. It's a windows machine so there is no /etc folder.

On the off chance, I tried:
"C:\Program Files\Git\usr\bin\ssh.exe" -vvv -F .ssh\config ChatServer

And that works! The -F specifies the config file, but you apparently have to give it the name of the entry to use in the config file.

So now the question is, how does one configure Git ssh to look in the right place.? Google finds:
https://stackoverflow.com/questions/9513712/git-ssh-client-for-windows-and-wrong-path-for-ssh-config-file
which indicates the HOME environmental value should be %USERPROFILE% but on my system is it C:\SPB_Data which DOES contain an .ssh and other configuration files. It also looks like platformIO has put a ton of stuff in there, so I'm not going to mess with it for now. I have a project in work that I need it for and when I'm done with that, I can come back and address this issue.

I assume the right thing to do at this point is close this issue. If someone else has the same problem, they can see if they have the same HOME environmental variable issue and if they are willing to change it, then they can see if that fixes the problem.

@zeegin
Copy link

zeegin commented Jan 9, 2020

I have the same problem: local user is used instead of remote user, that settled in .ssh config file.
And i have no picklist to change username, only popup for password.

@roblourens
Copy link
Member

roblourens commented Jan 9, 2020

Thanks for confirming, @JamesNewton. I guess I have no clue why it has worked on the windows machines I've tested, where HOME is not set. You can also set the remote.SSH.configFile setting to work around this, and then I will set the -F flag.

Maybe I should just always set -F, I'm not sure. I wanted ssh to do the right thing itself.

@roblourens roblourens added bug Issue identified by VS Code Team member as probable bug and removed info-needed Issue requires more information from poster labels Jan 9, 2020
@roblourens roblourens self-assigned this Jan 9, 2020
@roblourens roblourens added this to the January 2020 milestone Jan 9, 2020
@JamesNewton
Copy link
Author

This appears to be related: #1146

Setting the remote.SSH.configFile to the C:\Users\LocalUser\.ssh\config file under Remote-SSH: Settings appears to have resolved the problem. I was able to connect to the remote server and browse files.

When I tried to edit a file, the connection was lost and the I couldn't connect to it at all. I've restarted the VM (It's a google compute engine). Interestingly enough, they changed the external IP as a result, which confused me until I realized it. LOL. Now I can connect via their web interface and via PuTTY again, and the SFTP extension works for me. I'm a big gun shy but I'm sure it was just a coincidence. I'll give it another go tomorrow.

@OneCyrus
Copy link

OneCyrus commented Feb 7, 2020

same issue here. setting the configFile in VSCode resolves this issue. Also the known_hosts file has a similiar issue. The extension saves to the drive H: and ignores the one in the userprofile. (i guess because of reolving /h/.ssh/ to the drive H: instead of home.

@roblourens roblourens modified the milestones: February 2020, March 2020 Feb 26, 2020
@roblourens
Copy link
Member

roblourens commented Mar 16, 2020

Closing this in favor of #2512

@roblourens roblourens removed this from the March 2020 milestone Mar 16, 2020
@roblourens roblourens added *duplicate Issue identified as a duplicate of another issue(s) and removed bug Issue identified by VS Code Team member as probable bug labels Mar 16, 2020
@vscodebot vscodebot bot locked and limited conversation to collaborators Apr 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*duplicate Issue identified as a duplicate of another issue(s) ssh Issue in vscode-remote SSH
Projects
None yet
Development

No branches or pull requests

6 participants