# SSH access

Although the web-based JupyterLab interface is the recommended way to access Purdue AF, it is also possible to connect to your session from a terminal via SSH.

> [!NOTE]
>
> SSH connects you **to your running AF session**, not to a separate login node — start the session first, in a web browser or with an [AI agent](<https://analysis-facility.physics.purdue.edu/guide-agentic-interface/index.md>). If you would rather work in a full local IDE, see [Local IDE access](<https://analysis-facility.physics.purdue.edu/guide-ide-connection/index.md>).

## JupyterHub API token

SSH, [local IDEs](<https://analysis-facility.physics.purdue.edu/guide-ide-connection/index.md>), and [AI agents on your own machine](<https://analysis-facility.physics.purdue.edu/guide-agentic-interface/index.md#set-up>) authenticate to Purdue AF with a JupyterHub API token. To obtain one, open [https://cms.geddes.rcac.purdue.edu/hub/token](<https://cms.geddes.rcac.purdue.edu/hub/token>) (or, in JupyterLab, go to `File → Hub Control Panel` and click the `Token` tab), then click `Request new API token` and copy the token string.

On your local machine, save the token in a file only you can read: run these two commands, paste the token, and press `Ctrl-D`.

```shell
mkdir -p ~/.config/purdue-af
(umask 077; cat > ~/.config/purdue-af/token)
```

The SSH alias below and the IDE setup read the token from this file. When you request a new token, save it the same way.

> [!WARNING]
>
> **Treat the token like a password**
>
> The token gives full control over your AF session — do not share it or commit it to a Git repository.

## Instructions

1. **Start an AF session in the normal way**

   In a web browser, [log in to Purdue AF and start a session](<https://cms.geddes.rcac.purdue.edu>).
2. **Obtain a [JupyterHub API token](<#jupyterhub-api-token>)** — you will need it in the next step.
3. **Log in to your session from an external terminal**

   ```shell
   ssh <username>@jupyterhub-ssh.cms.geddes.rcac.purdue.edu
   ```

   - If you are using a CERN or FNAL account, remember that your username must include the `-cern` or `-fnal` suffix, respectively — see [Login methods](<https://analysis-facility.physics.purdue.edu/login-methods/index.md>).
   - Instead of a password, paste the **token** obtained in the previous step.
4. **(Optional) Set up an alias in `.bashrc`**

   By adding the following line to `~/.bashrc` or `~/.bash_profile` on your local machine, you can avoid copy-pasting the token every time. It reads the [saved token file](<#jupyterhub-api-token>) and needs the `sshpass` utility installed on the local machine.

   ```shell
   alias purdue-af='sshpass -f ~/.config/purdue-af/token ssh <username>@jupyterhub-ssh.cms.geddes.rcac.purdue.edu'
   ```

   Now simply running the `purdue-af` command will immediately connect you to Purdue AF, provided that you have already started a session.

## Caveats

> [!TIP]
>
> If you encounter any formatting issues while working at Purdue AF via an SSH connection (for example, broken lines in the Vim text editor), try running the `resize` command.

> [!WARNING]
>
> **No SFTP / scp support**
>
> `scp` to and from this SSH server does not work. To copy files with `scp`, connect the other way: from an AF terminal into your own computer, once it accepts SSH logins ([macOS](<https://support.apple.com/guide/mac-help/allow-a-remote-computer-to-access-your-mac-mchlp1066/mac>), [Ubuntu](<https://help.ubuntu.com/stable/ubuntu-help/sharing-secure-shell.html.en>), [Windows](<https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/factoryos/connect-using-ssh?view=windows-11>)):
>
> ```shell
> scp myfile.root <local-username>@<your-computer-address>:/path/on/local/machine/
> ```
>
> For other ways to move files, see [Uploading and downloading files](<https://analysis-facility.physics.purdue.edu/interface/index.md#uploading-and-downloading-files>).
