AWS does not natively support SSH-ing into SageMaker notebook instances, but nothing really prevents you from setting up SSH yourself.
The only problem is that these instances do not get a public IP address, which means you have to either create a reverse proxy (with ngrok for example) or connect to it via bastion box.
Steps to make the ngrok solution work:
- download ngrok with
curl https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip > ngrok.zip
unzip ngrok.zip
- create ngrok free account to get permissions for tcp tunnels
- run
./ngrok authenticate
with your token
- start with
./ngrok tcp 22 > ngrok.log &
(& will put it in the background)
- logfile will contain the url so you know where to connect to
- create
~/.ssh/authorized_keys
file (on SageMaker) and paste your public key (likely ~/.ssh/id_rsa.pub
from your computer)
- ssh by calling
ssh -p <port_from_ngrok_logfile> [email protected]
(or whatever host they assign to you, it;s going to be in the ngrok.log)
If you want to automate it, I suggest using lifecycle configuration scripts.
Another good trick is wrapping downloading, unzipping, authenticating and starting ngrok into some binary in /usr/bin so you can just call it from SageMaker console if it dies.
It's a little bit too long to explain completely how to automate it with lifecycle scripts, but I've written a detailed guide on https://biasandvariance.com/sagemaker-ssh-setup/.