Launch an SSH Server

If you like controlling your coding setup, consider using your own local VS Code instead of the hosted version. By setting up an SSH Server, you can run your code directly on your server, tapping into its robust cloud resources. This way, you maintain full control over your development environment, customizing VS Code with your favourite extensions and settings.

How to find your SSH Public Key?

Your SSH public key is typically stored in the ~/.ssh/ directory on your local machine. Look for a file ending in .pub, which contains the public key. For example:

  • id_rsa.pub(default key)

You can find your public key using the following command:

For Windows: type $home\.ssh\id_rsa.pub( windows powershell)

For Mac/Linux: cat ~/.ssh/id_rsa.pub

Creating a New SSH Key Pair

If you don't have an SSH Key Pair. You can generate one using the command:

ssh-keygen -t rsa

You can refer to this Link for generating an SSH Key Pair.

Installing ProxyTunnel

To install proxytunnel , follow the steps below for your Operating System:

Windows

Open PowerShell and run the following command:

Invoke-Expression (Invoke-WebRequest -Uri "https://raw.githubusercontent.com/truefoundry/infra-charts/refs/heads/main/scripts/windows_proxytunnel_install.ps1" -UseBasicParsing).Content

MacOS

brew install proxytunnel

Ubuntu

sudo apt-get update
sudo apt-get install proxy-tunnel

Other Linux Distros

Find proxytunnel in your package manager respositories
Or Build from Source: https://github.com/proxytunnel/proxytunnel

Connect Local VS Code with SSH

To connect Visual Studio Code to a remote SSH server, follow these steps:

  1. Install the extension: Remote-SSH
  2. After installing the extension, reload VS Code to ensure all changes are applied.
  3. Once VS Code reloads, you’ll see a new icon labeled Remote Explorer in the activity bar on the left side. Click on this icon to manage your SSH connections.
  4. Enter your password or passphrase to complete the connection.

Adding more users to SSH Server

To add more users to the SSH Server. You need to add the SSH keys to the users to the mkdir -p /home/jovyan/.ssh/authorized_keys

mkdir -p /home/jovyan/.ssh

echo "ENTER_PUBLIC_KEY" >> /home/jovyan/.ssh/authorized_keys

You can add multiple users with this. You can also remove users from this file as required.

Copying Files from SSH Server to Local Machine

To copy files from an SSH server to your local machine, use the following command in PowerShell. Make sure to update the placeholders with the correct values for your environment.

scp -r <deploymentName>:<remote-file-path> <local-file-path>

<deploymentName>: The name of the SSH server on the platform
<remote-file-path>: The path to the file or directory on the SSH server that you want to copy.
<local-file-path>: The destination path on your local machine where you want to save the copied file.

Copying Files from Local Machine to SSH Server

To copy files from your local machine to an SSH server, use the following command in PowerShell. Make sure to update the placeholders with the correct values for your environment.

scp -r <local-file-path> {{deploymentName}}:<remote-file-path>

<deploymentName>: The name of the SSH server on the platform
<remote-file-path>: The destination path on the SSH server where you want to save the copied file.
<local-file-path>: The path to the file or directory on your local machine that you want to copy.

Using rsync to Copy Files Between Local Machine and SSH Server

rsync is a tool for synchronizing files and directories between a local machine and a remote server via SSH. It only transfers the changes made to files, making it efficient for backups and file synchronization.

Copying Files from Local Machine to SSH Server

To copy files from your local machine to an SSH server using rsync, use the following command:

rsync -avz <local-file-path> <deploymentName>:<remote-file-path>

<deploymentName>: The name of the SSH server on the platform
<remote-file-path>: The path to the file or directory on the SSH server that you want to copy.
<local-file-path>: The destination path on your local machine where you want to save the copied file.

  1. The -a flag enables archive mode, preserving file permissions and timestamps.
  2. The -v flag enables verbose output, so you can see the progress of the transfer.
  3. The -z flag enables compression during transfer, which can speed up the process for larger files.

Copying Files from SSH Server to Local Machine

To copy files from an SSH server to your local machine using rsync, use the following command:

rsync -avz {{deploymentName}}:<remote-file-path>:<remote-file-path> <local-file-path>

<deploymentName>: The name of the SSH server on the platform
<remote-file-path>: The path to the file or directory on the SSH server that you want to copy.
<local-file-path>: The destination path on your local machine where you want to save the copied file.

  1. The -a flag enables archive mode, preserving file permissions and timestamps.
  2. The -v flag enables verbose output, so you can see the progress of the transfer.
  3. The -z flag enables compression during transfer, which can speed up the process for larger files.

Create More Python Environments

You can create python version with the following commands:

conda create -n my-new-env

# run the following command to create python environment with different python version
conda create -n py39-env python=3.9

Install Apt packages in the SSH Server

By default anything you install outside of home directory will NOT be persistent across notebook restarts. This means all apt installs (done directly from notebook) will NOT be persistent across restarts of notebook.

To make these apt packages persistent across restarts, you can add a "Build Script" in the notebook as follows

For example, here is a sample build script to install ffmpeg package:

sudo apt update
sudo apt install ffmpeg