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
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.
Related
I can ssh into a remote machine.
I then try to connect to a jupyter notebook job that I started on one of the nodes of the remote machine:
ssh -L 8069:localhost:8069 me#remote.machine ssh -L 8069:localhost:8069 me#node14
This has always worked fine in the past.
When I execute this lately, nothing happens until I eventually get a time out message. If I cancel it and then try to simply ssh into the remote machine again, it again does nothing until I get the error message:
ssh: connect to host remote.machine port 22: Connection timed out
I am trying to figure out if this is a problem at my end or at the remote machine. If it's the latter I can't understand why I am able to ssh to the remote machine fine until I try the
ssh -L 8069:localhost:8069 me#remote.machine ssh -L 8069:localhost:8069 me#node14
connection.
You are trying to do a double ssh connection: one to remote.machine and then another one to node14.
The problem seems to be the ssh process in the node14 machine. So, you can connect to the first machine but no to the second one. Ask your administrator to enable the sshd process in node14
You can test this case by logging into remote.machine via:
ssh -L 8069:localhost:8069 me#remote.machine.
Once you get shell access you can try the connection to node14 via:
ssh -L 8069:localhost:8069 me#node14.
According to the description, this last try should fail with the timeout.
ssh_client =paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.load_system_host_keys()
ssh_client.set_missing_host_key_policy(paramiko.WarningPolicy)
ssh_client.connect(hostname='abc',username='admin',password='admin')
with SCPClient(ssh_client.get_transport()) as scp:
scp.put(local_path='example.txt',remote_path='/abc')
I am trying to connect to a Windows system and send a file example.txt to it. But if I run the script, it gives the following error when sending a file to a windows system
paramiko.ssh_exception.NoValidConnectionsError: [Errno None] Unable to connect to port 22 on 'IP Address'
Help would be appreciated.
Edit: The Windows system that I am sending the file to runs a Windows 2008 server.
If you want to connect with Paramiko SSH/SFTP/SCP library to a machine, the machine must be running SSH/SFTP/SCP server.
Windows does not come with SSH/SFTP/SCP server running by default.
See Windows SSH Servers? question on Super User.
I have a remote Linux server setup where I am hosting a python script. The requirement is to connect to MongoDB that is hosted in a local windows machine. I understand that we can't directly access MongoDB as it allows only localhost:27017 by default.
Tried updating the mongo.cfg file by changing the properties under "net". However this didn't help. Can someone help me out in this case. I am getting the error below:
10.30.118.230:27017: [Errno 111] Connection refused
This is the code:
from pymongo import MongoClient
client = MongoClient("mongodb://{username}:{password}#{windows_system_ip_whereMongoDb_is_hosted}/{dbname}")
db = client.{dbname}
try:
db.command("serverStatus")
except Exception as e:
print(e)
else:
print("You are connected!")
client.close()
BY default windows firewall block all input connections in port 27017, you should enable the port 27017 in windows firewall to allow the connections through the port.
Configure Windows netsh Firewall for MongoDB
This is a newbie question for TCP-based communication in Python. I am trying to establish a TCP-based communication between two *NIX systems via an SSH tunnel and the Python socket module. I have used the two first examples "echo server" and "echo client" from this Python MOTW website: http://www.doughellmann.com/PyMOTW/socket/tcp.html.
The communication worked fine on the same *NIX system (HOST1) but failed over the ssh tunnel.
I logged into the second *NIX system with ssh -L 10000:HOST2:10000 USERNAME#HOST2. Then I played around and tried to establish the communication in the same manner by starting the python script for the server on HOST2 and the script for the client on HOST1. This I got on stderr:
python test_socket_client.py
connecting to localhost port 10000
Traceback (most recent call last):
File "test_socket_client.py", line 10, in <module>
sock.connect(server_address)
File "<string>", line 1, in connect
socket.error: [Errno 111] Connection refused
When I started server and client vice versa on HOST1 and HOST2, respectively, I got the same message.
What am I doing wrong?
Your server binds its socket to localhost:10000 -- which means it listens to connections from the loopback interface only. The SSH command line instructs SSH to tunnel local connections to port 10000 to connections to HOST2:10000. Your client Python program connects to localhost:10000, and the remote end of the SSH link then tries to connect to HOST2:10000. Even though that's the same port and the same machine as your socket is bound to, it's a different interface, to which your socket is not listening.
Change the SSH command line to ssh -L 10000:localhost:10000 USERNAME#HOST2, or bind your server's listening socket to all interfaces: server_address = ('', 10000). The empty string serves as INADDR_ANY.
Of course, what Gary van der Merwe said is true: SSH would need to be running at the time you run your client Python program on HOST1.
I would check that your server is listening on the server host, and that the ssh client is listening on the client host. You can run netstat -tnlp to check this.
Are you sure that your ssh client is still open when you are running your client. You either need to run shh in one terminal, and your client in another, or run ssh -Nf which causes ssh to go to the background after it has authenticated.
I wrote an XML RPC server in python and a simple Test Client for it in python. The Server runs on a linux box. I tested it by running the python client on the same linux machine and it works.
I then tried to run the python client on a Mac and i get the following error
socket.error: (61, 'Connection Refused')
I can ping and ssh into the linux machine from the Mac. So i dont think its a configuration or firewall error.
Does anyone have any idea what could be going wrong?
The code for the client is as below:
import xmlrpclib
s = xmlrpclib.ServerProxy('http://143.252.249.141:8000')
print s.GetUsers()
print s.system.listMethods()
"Connection Refused" means the connection was REFUSED - the machine 143.252.249.141 is up, and in the network, but is not accepting connections on port 8000 - it is actively refusing them.
So maybe the server software isn't running on the server? Or is running in another port? Or is bound to a different IP address?