0

My requirement is to automate the transfer of files, and running commands on the Windows VM, which is currently a manual process where I log in to the VM via RDP (and it prompts me for my username/password of my account).

I have been doing a bit of digging on this, as I am able to automate the same thing for a Linux VM where no such AAD based authentication exists and I use the paramiko library to transfer content from my PC to the VM and run bash commands.

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

# Connect to the server
try:
    client.connect(host, username=username, password=password)
    
    # Initialize the SFTP client
    sftp = client.open_sftp()
    
    # Transfer the file
    sftp.put(local_file_path, remote_file_path)
    print(f"File {local_file_path} has been transferred to {remote_file_path} on the remote server.")
    _stdin, _stdout,_stderr = client.exec_command("ls random*")

(Omitted content for brevity and confidentiality)

However, getting a set of credentials to log in to the Windows VM isn't allowed as per the org policy.

I am not really able to find any online resources on the same, beyond this and this but in the latter, it seems all be related to a simpler scenario where there is a username/password combination. I am investigating the usage of Pywinauto to try this out, but I am still not really sure on what the best approach really is. Personally, I would prefer to use Python but I am amenable to any solution at this point (or at least being pointed in the right direction).

5
  • Can you clarify what you can and cannot do, and from/to what kind of devices? Those same AAD credentials can be used for SMB file shares or WinRM access in certain situations, especially if your devices are both AAD-joined. Does this process need to run without you? If so, you'll need a service account of some sort created anyways, which could define more of what you need. If nothing else, OpenSSH server runs fine on windows too
    – Cpt.Whale
    Commented Jun 4 at 17:57
  • This process should be able to run without anyone @Cpt.Whale. Service account creation is something I have discussed with the TL, but whether I will get a file or key/value pairs is something I need to figure out. What I can confirm at this moment is that the AAD Cred (for my account) is to be used to for log in. I have a separate service account that is used for authenticating a login for Linux VMs, but the same one cannot be used for logging into a Windows VM. Commented Jun 5 at 6:08
  • That by the way was the ideal solution, but I am actually open to anything. Commented Jun 5 at 7:06
  • For the OpenSSH thing, we did request for a ticket to open the said ports, but then I am trying to figure out how to automate the auth process. Commented Jun 5 at 7:08
  • @Cpt.Whale Please help. Any suggestions would be extremely helpful. As for SSH I found out the Windows VM is not listening for connections on port 22. I have raised a ticket with the IT Team of my client Commented Jun 6 at 10:16

0

You must log in to answer this question.

Browse other questions tagged .