Hi all,
This is my very first message, so few words about me. I’m a Data Engineer and mostly do scripting in Python, but recently I’ve created few web apps in Flask in a docker container, also looking into Django a bit.
Since security policy requires working through ssh tunneling, I have created a document for the team about creating ssh key and setting up a tunnel. Though for internal usage it is ok, our external users are less technically advanced and we would need to simplify the process.
This is how I create a tunnel:
ssh u1@example.com -D9521 -C -N
socks5 browser settings:
127.0.0.1:9521
url to access the application in browser:
http://172.1.0.1:81
Now I’m trying to write an app that creates an ssh tunnel and opens the app automatically. I’d need someone experienced with ssh tunneling to look into it and advise where is the issue.
import sys
import paramiko
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout
from PyQt5.QtWebEngineWidgets import QWebEngineView
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("cool app")
self.setGeometry(150, 150, 900, 700)
# Create a web browser widget
self.browser = QWebEngineView()
self.browser.setUrl(QUrl("http://172.1.0.1:81"))
# Create a layout for the main window
layout = QVBoxLayout()
layout.addWidget(self.browser)
# Create a central widget and set the layout
central_widget = QWidget()
central_widget.setLayout(layout)
self.setCentralWidget(central_widget)
# Create an SSH tunnel to the Azure Virtual Machine
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_key = paramiko.RSAKey.from_private_key_file('/home/user1/.ssh/id_rsa')
ssh.connect('example.com', username='u1', pkey=ssh_key, port=22, timeout=100)
ssh_transport = ssh.get_transport()
ssh_channel = ssh_transport.open_channel('direct-tcpip', ('172.1.0.1', 81), ('172.1.0.1', 81))
# Set the web browser URL to use the SSH tunnel
self.browser.setUrl(QUrl("http://172.1.0.1:81"))
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
For now the app opens the window, but after some time of waiting it shows error
172.1.0.1 took too long to respond.
Please advise.