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