How to create a ssh tunnel using python and paramiko?

后端 未结 5 725
攒了一身酷
攒了一身酷 2020-12-02 13:13

I\'m learning python. I need to tunnel creators to read information from a database and close the tunnel. I use paramiko but I have not worked with tonelem example. please g

5条回答
  •  青春惊慌失措
    2020-12-02 13:52

    I used paramiko for some project I had a year ago, here is the part of my code where I connected with another computer/server and executed a simple python file:

    import paramiko
    
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(hostname='...', username='...', password='...')
    stdin, stdout, stderr = ssh.exec_command('python hello.py')
    ssh.close()
    

    stdin, stdout and sdterr contain the inputs/outputs of the command you executed.

    From here, I think you can make the connection with the database.

    Here is some good information about paramiko.

提交回复
热议问题