Failed to create the ssh tunnel error could not establish session to ssh gateway

Forums : PythonAnywhere

sshtunnel.BaseSSHTunnelForwarderError: Could not establish session to SSH gateway

Hi,

I wrote the following code, but I get this error when I run it:

sshtunnel.BaseSSHTunnelForwarderError: Could not establish session to SSH gateway

Any idea on what could be the issue?
I’m using python 3.8 and I have a paid subscription on the .com site (not EU).

Thanks!


import mysql.connector
import sshtunnel
import pandas as pd

sshtunnel.SSH_TIMEOUT = 5.0
sshtunnel.TUNNEL_TIMEOUT = 5.0

with sshtunnel.SSHTunnelForwarder(
    ('ssh.pythonanywhere.com',22),
    ssh_username='myuser', ssh_password='mypass',
    remote_bind_address=('my_user.mysql.pythonanywhere-services.com',3306)
    ) as tunnel:
        connection = mysql.connector.connect(user='myuser', password='mypass',host='127.0.0.1', port=tunnel.local_bind_port,database='myuser$mydb')
        sql = 'SELECT * from history'
        df = pd.read_sql(sql, con=connection)
        print(df.head())
        connection.close()

Beloved premium user

Talch
|
4
posts
|



July 13, 2020, 5:52 p.m.

|
permalink

I see a lot of failed password attempts just before this post was sent and then many more successful SSH connections, so I’m guessing that you started using the correct password and that it’s working now.

Staff

glenn
|
8701
posts
|

PythonAnywhere staff
|



July 14, 2020, 9:58 a.m.

|
permalink

you got it right…I had the wrong password in the connector. Now it’s working properly.

Thanks!

Beloved premium user

Talch
|
4
posts
|



July 14, 2020, 11:23 a.m.

|
permalink

Great! Glad you got it working.

Staff

giles
|
11190
posts
|

PythonAnywhere staff
|



July 14, 2020, 1:10 p.m.

|
permalink

Hey there!

I don’t used ssh before and now I need a help !

server = sshtunnel.SSHTunnelForwarder(
(‘ssh_host’,22),
ssh_username=’myuser’, ssh_password=’mypass’,
remote_bind_address=(‘my_user.mysql.pythonanywhere-services.com’,3306)
)

i don’t know what to put in ssh_host :(

help me

deleted-user-8527094
|
2
posts
|



Dec. 13, 2020, 4:07 p.m.

|
permalink

Hi, ssh only works for paid accounts.

Staff

pafk
|
2441
posts
|

PythonAnywhere staff
|



Dec. 14, 2020, 10:06 a.m.

|
permalink

I am trying to setup a remote and secure connection to my database server running on ubuntu from my notebook with Windows 10. pgadmin4 allows to setup an SSH connection. I can setup the tunnel from the WSL terminal in windows, but I would prefer to set it up in pgadmin4 for convenience. I am not quite sure how to do it right. Whether to use localhost or the actual ip address of the server under the connection tab. Though the error message below seems to point out that the ssh-tunnel itself failed. I am sure that I can ssh to the host and the database is running as well.
I wonder whether it is actually possible to use this option under windows. Do I need to install an ssh client manually?
This is the error message that I get:
Unable to connect to server:
Failed to create the SSH tunnel. Error: Could not establish session to
SSH gateway

Related

node inspect on google cloud console setup firewall

I am trying to setup the firewall for accessing node inspect using my local chrome browser.
Does anybody have a good short guide and which tcp protocol do I need to enable.
I have a firewall rule active where the compute instance enables tcp:80. It worked in the past of a http server. How do I know which port to use for node inspect and how to enable it.
If found it myself. I have to use an ssh tunnel. https://nodejs.org/en/docs/guides/debugging-getting-started/#enabling-remote-debugging-scenarios
Enabling remote debugging scenarios
We recommend that you never have the debugger listen on a public IP address. If you need to allow remote debugging connections we
recommend the use of ssh tunnels instead. We provide the following
example for illustrative purposes only. Please understand the security
risk of allowing remote access to a privileged service before
proceeding.
Let's say you are running Node on remote machine, remote.example.com, that you want to be able to debug. On that
machine, you should start the node process with the inspector
listening only to localhost (the default).
$ node --inspect server.js
Now, on your local machine from where you want to initiate a debug client connection, you can setup an ssh tunnel:
$ ssh -L 9221:localhost:9229 user#remote.example.com
This starts a ssh tunnel session where a connection to port 9221 on your local machine will be forwarded to port 9229 on
remote.example.com. You can now attach a debugger such as Chrome
DevTools or Visual Studio Code to localhost:9221, which should be able
to debug as if the Node.js application was running locally.

Need to establish an SSH tunnel in Node.js or do it on the server

I'm going to connect to a remote database using an SSH tunnel. Currently, I'm not sure how long the server is alive, but I will check with my provider.
However, is it safe to assume that I will be able to connect to the database by running this command: ssh -fNg -L 1337:database-name:3306 user#ssh-server.com once on the client? Or do I need to establish a connection all the time? I know there exist some npm modules to connect via SSH.
Thanks in advance!

Access database on Windows server through VPN from nodejs running on Linux

I'm kind of lost in my current project. From a linux machine (Ubuntu server), running a code in nodejs I have to connect to a windows server, through VPN, and access a mySQL server running on it.
About the VPN server I only know it's Windows and I can easily connect to it by using the VPN conector on another Windows machine, I do not have access to that machine or know its parameters.
All I have is the IP of both VPN and database server inside that VPN, and username/password for VPN and database as well. Also I know that the VPN uses ms-chap v2.
I'm trying to use openvpn like that:
sudo openvpn --remote vpnIP --dev tun --ifconfig 127.0.0.1 dbIP
This does not show any error message but never request VPN's username/password
And what should I do from nodejs to access the database once VPN is created?
As I've said, I'm very lost on that! Any tip will be welcome!
Unless something else is specified, a Windows based VPN almost always uses PPTP. You can not connect with OpenVPN. You have to use a PPTP client.
The Ubuntu package is pptp-linux.
There is a detailed explanation on how to configure it here.
In a nutshell (I assume you have no GUI on a server),
you can create a tunnel with :
pptpsetup --create my_tunnel --server <server_address> --username <username> --password '<password>' --encrypt
Configuration files will be created in /etc/ppp. You can then connect (in debug mode) with:
pon my_tunnel debug dump logfd 2 nodetach
or simply (once it work) :
pon my_tunnel
and stop it with :
poff my_tunnel
If the server is a gateway, you may need to add a route, something like :
ip route add 192.168.1.0/24 dev ppp0
You may want Network Manager with a plugin network-manager-pptp, also see this wiki
https://help.ubuntu.com/community/VPNClient#PPTP

Cannot connect to CVS repo from outside lan

I recently installed cvs onto by ubuntu server (11.10). I am able to connect to my repos via eclipse IDE from within my lan by using the server name. However, when I use the IP address instead I cannot connect.
This error is given: "Cannot connect to host: Connection refused".
I have port forwarding on and can connect to apache2, mysql, etc. from outside my lan just fine.
I found this when I was Googling a bit.
http://kulitkulit.wordpress.com/2009/08/06/installation-cvs-ubuntu-jaunty/

Perforce “Connect to server failed” when connecting to xxxxx.dyndns.org, but it works via 192.168.1.75

So I've had a Perforce server running on my MacPro for several years. It is set to register itself as xxxxx.dyndns.org, so other users can connect from off my LAN.
Suddenly, today, I can no longer connect via xxxxx.dyndns.org:1666. I get an error:
Connect to server failed; check $P4PORT.
TCP connect to xxxxx.dyndns.org:1666 failed.
connect: some.ip.address.:1666: Connection refused
If I go to a bash shell and do ping xxxxx.dyndns.org, it comes up with some.ip.address and says it pings fine.
So if I can connect via the LAN IP address, and can ping the computer with the dyndns.org address, and the router is set to forward 1666 to the computer hosting the P4 server, what else could be wrong?
Got this answered. Note the use of dyndns.org up there. Their free services have been turned off. I rewired it to use duckdns.org and now it's working fine.

#python #ssh #vpn #ssh-tunnel

Вопрос:

Возможно, это необычный вопрос, поскольку я знаю, что мой код работает!

Короче говоря, я пытаюсь создать SSH-туннель с помощью Python (используя библиотеки sshtunnel и paramiko).

Этот код отлично работает, если я отключу клиент Nord VPN для Windows, который я запускаю на своем локальном компьютере, однако (возможно, неудивительно), когда он включен, SSH-туннель не подключается.

В VPN-клиенте Nord я могу настроить раздельное туннелирование только для файлов .exe, поэтому там я могу указать SSH и вручную использовать SSH, даже когда клиент запущен.

Итак, кто-нибудь знает о работе здесь, где я могу либо обойти Nord VPN программно, либо любые другие предложения, которые могут помочь (я пробовал обычные предложения, такие как изменение протокола на OpenVPN и отключение кибербезопасности в графическом интерфейсе клиента Nord VPN)?

 
def ssh_tunnel():

    EC2_URL = IP_ADDRESS
    username = "USER_NAME"
    pem_file = 'FILE_NAME.pem'

    # Create the tunnel
    server = SSHTunnelForwarder(
        (EC2_URL, yyyy),
        ssh_username=username,
        ssh_pkey=pem_file,
        remote_bind_address=(EC2_URL, xxxx),
        local_bind_address=('xx.x.x.x', xxxx)
    )
    # Starts the tunnel
    server.start()

    # Prints the local bind port
    print(server.local_bind_port)

    # Closes the tunnel
    server.stop()
 

На всякий случай, если это поможет, вот фактическая ошибка (хотя я предполагаю, что, учитывая, что проблема известна, она может не добавить слишком много)!

 2021-04-26 18:20:54,319| ERROR   | Could not connect to gateway x.x.x.x:x : Unable to connect to x.x.x.x: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Traceback (most recent call last):
  File "xxx.py", line 284, in <module>
    ssh_tunnel()
  File "xxx.py", line 201, in ssh_tunnel
    server.start()
  File "xxxlibsite-packagessshtunnel.py", line 1331, in start
    self._raise(BaseSSHTunnelForwarderError,
  File "xxxlibsite-packagessshtunnel.py", line 1174, in _raise
    raise exception(reason)
sshtunnel.BaseSSHTunnelForwarderError: Could not establish session to SSH gateway
 

Понравилась статья? Поделить с друзьями:
  • Failed to create signature error набор ключей не определен 0x80090019
  • Failed to import package with error couldn t decompress package
  • Failed to create signature error действие было отменено пользователем 0x8010006e
  • Failed to create registry error code 5 как исправить
  • Failed to create pixel shader 0 for null name error code 80070057 apex