Created
October 14, 2020 21:37
-
-
Save voutilad/3a4d33ab589b059191e35d812a4e8737 to your computer and use it in GitHub Desktop.
Make gcloud work better on Win10 with OpenSSH
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/surface/compute/config_ssh.py b/lib/surface/compute/config_ssh.py | |
index 41bd6794..f9d14517 100644 | |
--- a/lib/surface/compute/config_ssh.py | |
+++ b/lib/surface/compute/config_ssh.py | |
@@ -193,7 +193,7 @@ def _CreateAlias(instance_resource): | |
return '.'.join(parts) | |
-def _BuildComputeSection(instances, private_key_file, known_hosts_file): | |
+def _BuildComputeSection(user, instances, private_key_file, known_hosts_file): | |
"""Returns a string representing the Compute section that should be added.""" | |
temp_buf = [] | |
@@ -206,7 +206,8 @@ def _BuildComputeSection(instances, private_key_file, known_hosts_file): | |
temp_buf.extend(textwrap.dedent("""\ | |
Host {alias} | |
HostName {external_ip_address} | |
- IdentityFile {private_key_file} | |
+ User {user} | |
+ IdentityFile "{private_key_file}" | |
UserKnownHostsFile={known_hosts_file} | |
HostKeyAlias={host_key_alias} | |
IdentitiesOnly=yes | |
@@ -214,6 +215,7 @@ def _BuildComputeSection(instances, private_key_file, known_hosts_file): | |
""".format(alias=_CreateAlias(instance), | |
external_ip_address=external_ip_address, | |
+ user=user, | |
private_key_file=private_key_file, | |
known_hosts_file=known_hosts_file, | |
host_key_alias=host_key_alias))) | |
@@ -349,12 +351,13 @@ class ConfigSSH(base.Command): | |
except MultipleComputeSectionsError: | |
raise MultipleComputeSectionsError(ssh_config_file) | |
else: | |
- ssh_helper.EnsureSSHKeyIsInProject( | |
- client, ssh.GetDefaultSshUsername(warn_on_account_user=True), None) | |
+ user = ssh.GetDefaultSshUsername(warn_on_account_user=True) | |
+ ssh_helper.EnsureSSHKeyIsInProject(client, user, None) | |
instances = list(self.GetRunningInstances(client)) | |
if instances: | |
compute_section = _BuildComputeSection( | |
- instances, ssh_helper.keys.key_file, ssh.KnownHosts.DEFAULT_PATH) | |
+ user, instances, ssh_helper.keys.key_file, | |
+ ssh.KnownHosts.DEFAULT_PATH) | |
else: | |
compute_section = '' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment