This repository provides an efficient setup for connecting to Kaggle notebooks via SSH using ngrok
.
- Kaggle Notebook
- Ngrok account
- A public repository containing your
authorized_keys
file
Warning
Due to recent Ngrok policy changes, using its services might be limited:
- TCP endpoints are only available on a free plan after adding a valid payment method to your account.
- Data Transfer Limits: Free account are limited to 1GB data transfer.
-
Open your terminal.
-
Generate a new SSH key pair by running:
ssh-keygen -t rsa -b 4096 -C "kaggle_remote_ssh" -f ~/.ssh/kaggle_rsa
-
Follow the prompts. Save the keys in the location ~/.ssh/kaggle_rsa
-
Locate your public key by running:
cat ~/.ssh/kaggle_rsa.pub
-
Copy the contents of the public key.
-
Go to GitHub and log in.
-
Create a new GitHub repository (e.g.,
SSH_public_key
). -
In the repository, create a file name whatever you want, let's say
authorized_keys
and paste your SSH public key into this file. -
Save and commit the file.
-
Click to
authorized_keys
file then click toraw
then copy the url like this
- Go to Ngrok and sign in or create an account.
- Navigate to the "Authtoken" section of the dashboard.
- Copy your auth token.
- Create a Kaggle notebook, choose your desired GPU, adjust persistence if needed, enable internet access.
- Run the following commands in a notebook cell:
%%bash
# Step 1: pre-capture environment variables
printenv > /kaggle/working/kaggle_env_vars.txt
# Step 2: Clone the repository, install requirements, and set permissions
git clone https://github.com/buidai123/Kaggle_VSCode_Remote_SSH.git /kaggle/working/Kaggle_VSCode_Remote_SSH
cd /kaggle/working/Kaggle_VSCode_Remote_SSH
pip install -r requirements.txt
chmod +x install_extensions.sh
chmod +x setup_kaggle_ssh.py
chmod +x setup_ssh.sh
# Step 3: Run the SSH setup
./setup_ssh.sh <your_authorized_key_repo>
# Step 4: Run the ngrok setup with Python
python3 setup_kaggle_ssh.py <you_authtoken>
- Wait until the setup is complete as shown in the image below.
Note
i use password here as the fallback if the ssh key doesn't work properly so if you're using Linux you can ignore this password
- Install the required VSCode extensions.
- Hit
ctrl
+shift
+p
, search forRemote-SSH: Connect to Host
and chooseConfigure SSH Hosts
- Select the first option or paste the path to your config file in the settings.
- Update your
~/.ssh/config
file on your local machine with the connection details:
Host "Kaggle"
HostName <hostname from script output>
User root
Port <port from script output>
IdentityFile <path to your private key>
- Save it and hit
ctrl
+shift
+p
again. ChooseConfigure SSH Hosts
and select the host name you set earlier.
-
A new window will appear; if prompted for the OS, choose Linux, then continue and enter your password if required. That's it!
-
Note that the first time you connect if it said
could not connect...
then you need to empty your config file and this time chooseAdd New SSH Host...
and paste this command in
ssh root@<HostName> -p <Port>
Replace <HostName>
and <Port>
like before
- After connected go to kaggle folder(you might want to work there). You can open terminal and run the following command to install necessary extension
./working/Kaggle_VSCode_Remote_SSH/install_extensions.sh
Tip
If you're using chromium base browser you can disable battery saver mode for the Kaggle tab by going to chrome://discards
click to toggle to to disable auto discardable
- Multiple Keys: Store each key pair in separate files and configure SSH clients to use the appropriate key.
- Security: Secure your private keys and distribute only public keys.
Important
Remember to add a CC to your Ngork account first
- Connectivity Issues: Ensure that your Kaggle Notebook is running and that the ngrok tunnel is active.
- Permission Denied: Verify permissions and paths to your SSH keys and ensure the public key is authorized in the Kaggle Notebook.
If you have any questions or need further assistance, feel free to reach out:
- Email: [email protected]