Skip to content

ADD: Support SSH to Windows Machine #477

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

cs7-shrey
Copy link
Contributor

@cs7-shrey cs7-shrey commented Mar 7, 2025

Description

What is this PR

  • Bug fix
  • Addition of a new feature
  • Other

Why is this PR needed?
Fixes Issue #450 : Support SSH to Windows Machine

What does this PR do?
Allows storing public key on the server during a SSH to a Windows Machine.

References

Issue #450

How has this PR been tested?

Minor testing with a windows machine.

Please explain how any new code has been tested, and how you have ensured that no existing functionality has changed
Connection and data transfer from a windows machine was tested.

Testing Approach

  • Create / update the SSH config for the windows machine
  • Click "Setup SSH Connection" and complete the setup for SSH keys
  • Now, to test if the SSH setup was successful, we can test in two ways:
    • a. Try SSHing into the windows machine with the private key created by datashuttle
      (use ssh -i <path_to_private_key>) (you may need to remove your own public key from the authorized keys file on windows since SSH will try to use all keys availabe, or you can try SSH with ssh -v to inspect the logs and see if your key was accepted.
    • b. Have a project on the windows machine and try transferring data to and from the windows machine
  • If the above two methods work, then it can be assumed that SSH setup was successful

Is this a breaking change?

No

Does this PR require an update to the documentation?

No

Checklist:

  • The code has been tested locally
  • Tests have been added to cover all new functionality
  • The documentation has been updated to reflect any changes
  • The code has been formatted with pre-commit

Copy link
Member

@JoeZiminski JoeZiminski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @cs7-shrey thanks a lot for this, it's a very clean implementation. I don't have many suggestions, I think this is probably good to go in its current form.

The main issue here will be testing, to test over a few different machines / windows versions and check everything is working okay, and then automate these tests. This is related to #208 and #100, which cover extending our test cases (some public, but some internal for our institute). Out of interest, how are you testing at the moment, could you expand the PR message to include a step-by-step of the testing approach?

I'll look into this further and get back to you ASAP! We will definitely move forward with this PR, I'm just not certain on the timeline as mentioned on the zulip chat. But I will try and test it over the next couple of weeks and get back to you here!

Thanks again! this is a very nice addition.

if "windows" in output:
return True

stdin, stdout, stderr = client.exec_command(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks nice, could you add a small docstring to explain the approach taken (I guess "ver" will not work in powershell terminal, only cmd so that it checked after "ver")?

f">> %USERPROFILE%\\.ssh\\authorized_keys"
)
client.exec_command(
"icacls %USERPROFILE%\\.ssh /inheritance:r /grant %USERNAME%:(OI)(CI)F"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a couple of comments here explaining what these steps do?

@cs7-shrey
Copy link
Contributor Author

@JoeZiminski I have made changes as you suggested. I wanted to ask one more thing. The current approach does not change file/directory permissions if the windows user is an admin as I assumed that admin accounts have the already required permissions and restrictions. Do you suggest explicitly setting up permissions for admin users too?

# double >> for concatenate
f"echo {key.get_name()} {key.get_base64()}"
f">> C:\\ProgramData\\ssh\\administrators_authorized_keys"
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it suggested to add commands to change file permissions for admin users?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point @cs7-shrey, I think it makes sense to assume file permissions are already granted, as you say. If it turns out that its causing problems in testing, we can add this later if required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants