DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • AI Agents Need an Identity Plane: Rethinking Enterprise Authorization for Autonomous Software
  • Catching Query Regressions Before Your Users Do
  • Engineering AI Accountability: Control the Execution Path, Not the Model
  • One Agent, Two Runtimes: Defining State Ownership Between Temporal and LangGraph

Trending

  • Designing Memory Architecture for Stateful AI Agents: Short-Term Context and Long-Term Persistence
  • Part 4: Multi-Agent Orchestration — Pairing Goose With Quarkus Flow State Machines
  • Member Spotlight: Shai Almong
  • Architecture Review Boards for Generative AI: A Framework for Governance, Risk Management, and Responsible Adoption

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Software Design and Architecture
  3. Performance
  4. Remote Code Execution on Windows Server From a Linux Server

Remote Code Execution on Windows Server From a Linux Server

A quick tutorial on how to execute scripts on a Windows server remotely from a Linux server using the Python module Paramiko.

By 
Geetha Rangaswamaiah
·
Oct. 02, 20 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
6.7K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Let's say a Workflow Management Framework of our choice based on the business needs works only on Linux. And let's say our jobs/scripts depend on some libraries that are only compatible with Windows. One of the solutions here could be to host the Workflow Management Framework on a Linux server and execute the jobs on a Windows server via SSH. So the jobs will be triggered on the Linux server and executed on the Windows server.

Paramiko is a Python implementation of the SSH protocol, providing both client and server functionality. It is a Python interface around SSH networking concepts. http://www.paramiko.org/

Let's get started.

Make sure SSH is enabled on both the servers.

Shell
 




x


 
1
ssh <hostname>



Install the Paramiko module on the Linux server.

Shell
x
 
1
pip install paramiko


On the Windows server, create a python file (winser_test.py) and add the below sample code.

Python
 




xxxxxxxxxx
1


 
1
import os
2

          
3
os.system("systeminfo")


 command prompt


On the Linux server, create a python file (linser_test.py) and add the below client code.

Python
 




xxxxxxxxxx
1
18


 
1
# import the library
2
import paramiko
3

          
4
# initialize the ssh client
5
ssh_client = paramiko.SSHClient()
6

          
7
# enable host auto-add policy 
8
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
9

          
10
# connect to windows server
11
ssh_client.connect(hostname = <hostname>, username = <username>, password = <password>, port = 22)
12

          
13
# execute the script on windows server
14
stdin, stdout, stderr = ssh_client.exec_command('python <path_to_the_file>winser_test.py')
15

          
16
# print the standard out and error (if any) 
17
print('stdout -- ', stdout.read())
18
print('stderr -- ', stderr.read())



Now, execute the linser_test.py script and that will in turn execute the winser_test.py on the Windows server.

execute winsertest on windows server


Reference: http://docs.paramiko.org/en/stable/

Linux (operating system) Execution (computing)

Opinions expressed by DZone contributors are their own.

Related

  • AI Agents Need an Identity Plane: Rethinking Enterprise Authorization for Autonomous Software
  • Catching Query Regressions Before Your Users Do
  • Engineering AI Accountability: Control the Execution Path, Not the Model
  • One Agent, Two Runtimes: Defining State Ownership Between Temporal and LangGraph

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook