Remote tcp connection in python with zeromq

I have a python client that needs to talk to a remote server that I am managing. They exchange data using zeromq. When I tested the client / server, everything worked. But now I have a client and server deployed in the cloud, each of which uses a different provider. My question is: what is the easiest way (secure) to make a connection? I assume that I can not pass the password, and even if I could assume that there are more secure alternatives.

I know how to establish an ssh connection without a password using ssh-keygen. Will this work? Will the client have to make an ssh connection to the server before sending tcp req? If there is a python library to help with this, that will be a big help.

Thank!

Update : So more than 24 hours have passed, and no one answered or answered. I think I'm getting closer to solve this, but not quite yet. I added my client key to .ssh / authorized_key on the server, and now I can ssh from client to server without a password. Then I followed this post on “Tuning PyZMQ Connections with SSH”. Here is what I have in my client code:

1    context = zmq.Context()
2    socket = context.socket(zmq.REQ)
3    socket.connect("tcp://localhost:5555")
4    ssh.tunnel_connection(socket, "tcp://locahost:5555", "myuser@remote-server-ip:5555")
5    socket.send_string(some_string)
6    reply = socket.recv()

This does not work. I really do not understand lines 3 and 4, and I suppose that I am something wrong. In addition, my server (hosted on linode) has the IP address “Default Gateway” and “Public IP” - in the tunnel connection, I specify only the public ip, which is also the ip that I use for ssh on the machine.

+4
2

, ZMQ - SSH. - , , , connect, tunnel_connection, .

, SSH, ZMQ REP. myuser@remote-server-ip:5555 myuser@remote-server-ip myuser@remote-server-ip:22.

import zmq
import zmq.ssh
context = zmq.Context()
socket = context.socket(zmq.REQ)
zmq.ssh.tunnel_connection(socket, "tcp://locahost:5555", "myuser@remote-server-ip")
socket.send(b"Hello")
reply = socket.recv()

, , pexpect, paramiko - . : Windows, paramiko - , - pexpect openssh Windows.

paramiko pexpect, paramiko=True tunnel_connection.

+10

, ssh Python iffy, paramiko fabric, , , .

:

ssh myuser@remote-server-ip -L 5050:localhost:5555 -N

: myuser@remote-server-ip, , localhost:5050 , ssh-, remote-server-ip , localhost:5555.

-L , -N , .

, , , zeromq localhost:5050, zeromq, .

5555:localhost:5555 ssh, , .

+1

Source: https://habr.com/ru/post/1531058/


All Articles