How to Achieve True SSH in RunPod

BY ZHEN LU - APRIL 25, 2022
RunPod allows you to get a terminal access pretty easily, but it does not run a true SSH daemon by default. There are plenty of use cases, like needing to SCP or connecting an IDE that would warrant running a true SSH daemon inside the pod. We'll go through the easiest ways to accomplish this in this article. We'll go through the following steps to get up and running...

Edit: All of this is now automated through our custom tensorflow, pytorch, and "RunPod stack" images (github). You can still follow this tutorial to get started in any custom image you want to use, though!

RunPod allows you to get a terminal access pretty easily, but it does not run a true SSH daemon by default. There are plenty of use cases, like needing to SCP or connecting an IDE that would warrant running a true SSH daemon inside the pod. We'll go through the easiest ways to accomplish this in this article. We'll go through the following steps to get up and running:

  • How to select a compatible pod

  • How to configure the pod to install and configure openssh automatically

  • How to get the correct connection command to SSH into your pod

Finding a Compatible Instance

All secure cloud pods are TCP enabled by default, so the easiest way to get a compatible pod is to deploy a secure cloud instance. If you'd rather browse or use community cloud, you can select "Browse" from the left side menu and look for instances that have the "TCP" badge under the internet speeds. We'll be going through the secure cloud route for this example, but using the community cloud browse method is very similar.

First choose how many GPUs you need for your instance, then hit select.

At this point, you can select any run template that you have configured. In this case, we're going to select the "Custom Container" option, as this will allow us to run any container we want!

Once you've selected this template, click on the "Customize Deployment" button. You should see a menu like this pop up:

Most of the setup takes place in this menu. The major things to check off are:

  • Expose TCP port 22

  • Copy/Paste the below in the "Docker Command" field

  • Make sure that you replace YOUR_PUBLIC_KEY with... your public key

bash -c "apt update;apt install -y wget;DEBIAN_FRONTEND=noninteractive apt-get install openssh-server -y;mkdir -p ~/.ssh;cd $_;chmod 700 ~/.ssh;echo YOUR_PUBLIC_KEY > authorized_keys;chmod 700 authorized_keys;service ssh start;sleep infinity"

Fill out the rest of the stuff however you like. I'm using the stock ubuntu image here. Hit OK, Continue, then choose whether you would like a spot instance or an on-demand instance and deploy. Your pod will begin initializing. This very fast for images that are used often, but may take some time if you are using an image that has not been run yet on the machine. It will usually take 20 seconds to 5 minutes. If you are concerned that something may not be working correctly, you can inspect the log output to debug whether it's a configuration issue.

Once your pod is initialized, you should see the "Connect" button enabled.

Click on this button, and it will bring you up a menu of connection options. The one we are most interested in is at the bottom.

Clicking on the field will automatically copy it to your clipboard. You may have to edit this command if you saved your private key somewhere else. You should now be able to run this command in a terminal window and get a real SSH tunnel!

Zhen is one of the co-founders of RunPod. He holds a PhD in Computational Chemistry and has lots of experience teaching, coding, and talking to people.

Want to join our growing community?
Chat with us on our Discord Server.
Prefer email? Contact us at support@runpod.io