0

I am trying establish remote desktop connection from a windows machine to other windows machine and have tried below scenarios -

import paramiko
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('IP',port = 3389, username='un',password='pwd')
print ("Connected to %s" % 'IP')
stdin, stdout, stderr = ssh.exec_command('ls -1 /root|head -n 5')
print ("STDOUT:\n%s\n\nSTDERR:\n%s\n" %( stdout.read(), stderr.read() )) 

Upon running above code i observed below error message

paramiko.ssh_exception.SSHException: Error reading SSH protocol banner[WinError 10054] An existing connection was forcibly closed by the remote host

Looked at this quetsion - python connecting to ssh An existing connection was forcibly closed by the remote host But, I haven't closed the connection in my code and still face the exception.

I looked at some forums and understood that for windows machine 3389 is the port for remote desktop connection and so used 3389 as port in my code.

I have also used port=22, ran the code and observed this exception:

paramiko.ssh_exception.NoValidConnectionsError: [Errno None] Unable to connect to port 22 on IP

I have also tried few - How to connect to a remote Windows machine to execute commands?

procedures stated here to make remote desktop connection. But couldn't establish the connection.

versions:

  • paramiko: 2.4.0
  • python: 3.6.4
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
User2014
  • 101
  • 3
  • 18

1 Answers1

0

You need SSH server on the server to connect with SSH.

There's no SSH server by default in Windows, so you cannot connect to port 22, unless you install some. See https://serverfault.com/q/648855/168875

You absolutely cannot connect to Remote desktop port 2289 with SSH.


Also, even if you install SSH server, it won't allow you to execute *nix command like ls on Windows. Neither it would magically create some root folder on Windows.

For that you additionally need to install some *nix-emulation on Windows, like Windows Subsystem for Linux or Cygwin.


Overall, your question like a conceptual misunderstanding.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • Thanks for your answer. I will follow the steps you specified. I am using Cygwin already to excute *nix commands. Also i am very new to Python and just started writing simple code snippets – User2014 Mar 12 '18 at 21:24
  • Cygwin comes with SSH server. You should have mentioned that you have Cygwin in the first place. – Martin Prikryl Mar 13 '18 at 06:46