Attemptiing to set up an SSH tunnel to a Google Colab instance using Ngrok. However, it encounters a ConnectionRefusedError, indicating that Ngrok is unable to establish a connection. This could stem from various issues such as misconfiguration of Ngrok, firewall restrictions, incorrect port forwarding, issues with the Colab instance, or limitations of Ngrok's free tier.
Error I am coming across
ConnectionRefusedError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/urllib3/connection.py in _new_conn(self)
202 try:
--> 203 sock = connection.create_connection(
204 (self._dns_host, self.port),
18 frames
ConnectionRefusedError: [Errno 111] Connection refused
The above exception was the direct cause of the following exception:
NewConnectionError Traceback (most recent call last)
NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7cda712b1f90>: Failed to establish a new connection: [Errno 111] Connection refused
The above exception was the direct cause of the following exception:
MaxRetryError Traceback (most recent call last)
MaxRetryError: HTTPConnectionPool(host='localhost', port=4040): Max retries exceeded with url: /api/tunnels (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7cda712b1f90>: Failed to establish a new connection: [Errno 111] Connection refused'))
During handling of the above exception, another exception occurred:
ConnectionError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
517 raise SSLError(e, request=request)
518
--> 519 raise ConnectionError(e, request=request)
520
521 except ClosedPoolError as e:
ConnectionError: HTTPConnectionPool(host='localhost', port=4040): Max retries exceeded with url: /api/tunnels (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7cda712b1f90>: Failed to establish a new connection: [Errno 111] Connection refused'))
I am performing below steps
# Install useful stuff
!apt-get update > /dev/null
!apt-get install --yes ssh screen nano htop ranger git > /dev/null
# SSH setting
!echo "root:hello" | chpasswd
!echo "PasswordAuthentication yes" > /etc/ssh/sshd_config
!echo "PermitUserEnvironment yes" >> /etc/ssh/sshd_config
!echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
!service ssh restart > /dev/null
# Download ngrok
!wget -q -c -nc https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
!unzip -qq -n ngrok-stable-linux-amd64.zip
# Run ngrok
authtoken = "2LSXUPuvhq7GioEKGLXOsTX4tUT_RX5wTzEfvKUTwZAkHfyo"
get_ipython().system_raw('./ngrok authtoken $authtoken -region ap && ./ngrok tcp 22 &')
!sleep 3
# Get the address for SSH
import requests
from re import sub
r = requests.get('http://localhost:4040/api/tunnels')
str_ssh = r.json()['tunnels'][0]['public_url']
str_ssh = sub("tcp://", "", str_ssh)
str_ssh = sub(":", " -p ", str_ssh)
str_ssh = "ssh root@" + str_ssh
print(str_ssh)
I've attempted to connect to the Colab server through Ngrok using this code, but unfortunately, I'm encountering connectivity issues.