Setting up SSH tunnel from mac to PC
Colab has security measures to prevent you from putting in any IP address in the Local Connections Settings dialog. These instructions mention that you can use gcloud command to point to a different machine using local port forwarding. However, it doesn’t show you how to do this for a mac to window set up (and maybe you don’t have gcloud installed). So, if you have a Windows PC with a GPU that you would like to run Python notebooks using colab on your mac (macbook), simply follow these instructions below:
- On Windows PC (Win 10 or 11)
- Install openssh server on Windows
- Turn on openssh server service to run automatically
- Windows key -> Services
- Find OpenSSH SSH Server service
- Right click Action > Properties
- In the Properties dialog, change Startup type to Automatic and confirm
- On Mac
- Create ssh key (if you don’t already have a SSH public key which you use)
- ssh-keygen -t rsa -b 4096 -C “<emailaddress>”
- Should generate a public / private key pair in ~/.ssh (id_rsa and id_rsa.pub), the latter file is the public key
- Create ssh key (if you don’t already have a SSH public key which you use)
- On Windows PC install
- Copy ~/.ssh/id_rsa.pub (from Mac) to %ProgramData%\ssh\adminstrators_approved_keys (on Windows)
- Set up permissions for administrators_approved_keys file
- icacls administrators_authorized_keys /inheritance:r
- icacls administrators_authorized_keys /grant SYSTEM:`(F`)
- icacls administrators_authorized_keys /grant BUILTIN\Administrators:`(F`)
- Restart openssh server through services or command line (net stop sshd & net start sshd)
- Startup Jupyter on Windows
- Type jupyter lab in a command prompt
- Copy localhost connection string with token (starts with https://localhost::8888/lab?token=<token>)
- On Mac
- Start SSH tunnel
- ssh -L 8888:localhost:8888 <windowsAccount>@192.168.1.xxx
- Start up colab instance in browser
- Click on “connect to a local runtime”
- Paste in localhost connection string from above
- Pro tip: I use google docs to share context across machines.
- Start SSH tunnel
- Troubleshoot
- ssh -v or ssh -v -v -v (connection issues)
- nc -z localhost 8888 || echo “no tunnel open” (test for liveness)