> ## Documentation Index
> Fetch the complete documentation index at: https://docs.infinitecompute.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Jupyter on your GPU

> Run JupyterLab on your GPU server and open it securely through an SSH tunnel.

Run Jupyter **on the server** and open it on your computer through an **SSH tunnel**. You get notebooks running on the GPU, and Jupyter stays private to you.

> [!NOTE]
>
> The commands on this page use the SSH config entry from your server's **Connect** box, so `<server-name>` is all you need. Set it up first: see [Save the connection once](https://docs.infinitecompute.ai/guides/ssh-keys-and-connecting.md#save-the-connection-once).

> [!WARNING]
>
> Don't open Jupyter's port to the internet, for example by adding a security group rule or running it on `0.0.0.0`. Anyone who can reach it can run code on your server. The SSH tunnel below keeps it private.

**1. Connect to your server**

```bash theme={null}
ssh <server-name>
```

**2. Install JupyterLab**

The ready-made images with PyTorch preinstalled have a Python environment at `/opt/pytorch`. On those, install JupyterLab into it:

```bash theme={null}
/opt/pytorch/bin/pip install jupyterlab
```

If this fails with `Permission denied`, your user isn't in the `sudo` group yet. This affects servers created from the current PyTorch images, and the fix is to add yourself once, then reconnect and run the install again:

```bash theme={null}
sudo usermod -aG sudo "$USER"
exit
```

On any other image, create an environment first, then use `~/venv` instead of `/opt/pytorch` in the commands on this page:

```bash theme={null}
python3 -m venv ~/venv
~/venv/bin/pip install jupyterlab torch
```

On Ubuntu, if `python3 -m venv` fails, install the `venv` module first with `sudo apt install -y python3-venv`.

**3. Start JupyterLab**

Still on the server, start it inside `tmux`, so Jupyter keeps running if your connection drops:

```bash theme={null}
tmux new -s jupyter
/opt/pytorch/bin/jupyter lab --no-browser --port 8888
```

Jupyter prints a URL containing `token=...`. Copy it. To leave `tmux` running in the background, press `Ctrl-b`, then `d`.

**4. Open the tunnel from your computer**

In a **new terminal on your own computer**:

```bash theme={null}
ssh -N -L 8888:localhost:8888 <server-name>
```

Leave it running. It forwards port 8888 on your computer to Jupyter on the server.

**5. Open Jupyter in your browser**

Paste the URL Jupyter printed, for example `http://localhost:8888/lab?token=...`.

## Check that the notebook sees the GPU

In a notebook cell:

```python theme={null}
import torch
print(torch.cuda.is_available())      # True
print(torch.cuda.get_device_name(0))  # your GPU's name
```

## Tips

* If port 8888 is already used on your computer, pick another local port, for example `ssh -N -L 9999:localhost:8888 <server-name>`, and open `http://localhost:9999`.
* To get back to Jupyter later, connect with `ssh <server-name>` and run `tmux attach -t jupyter`.
* To use the same Python environment in your terminal, run `source /opt/pytorch/bin/activate` (or `source ~/venv/bin/activate`).
* Notebooks are saved on the server's disk. See [Where your data lives](https://docs.infinitecompute.ai/guides/your-data.md).

## Related

> [card] [SSH keys and connecting](https://docs.infinitecompute.ai/guides/ssh-keys-and-connecting.md)
>
> Add a key, turn on SSH and connect.

> [card] [Where your data lives](https://docs.infinitecompute.ai/guides/your-data.md)
>
> What is kept, what is lost, and how to save results.

> [card] [Servers](https://docs.infinitecompute.ai/console/servers.md)
>
> Launch, connect, park and delete servers.

> [card] [Deploy a model](https://docs.infinitecompute.ai/guides/deploy-a-model.md)
>
> Serve an open model behind an OpenAI-compatible API.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.