Foundations to Frontier
Tests
C. Programming, Tools and HPC › C4 Linux and Systems

SSH and Remote Development

Most research computing happens on machines you never touch: clusters, cloud VMs, lab servers, robots in a field. SSH gives you an encrypted, authenticated shell on them, and on top of it file transfer, port forwarding to remote Jupyter or TensorBoard, jump hosts through bastions, and full remote editing. This topic covers key-based authentication and host-key verification (what the 'authenticity of host can't be established' prompt protects you from), the ~/.ssh/config file, ProxyJump, local and remote port forwarding, scp/sftp/rsync, keeping sessions alive with tmux, and remote IDEs. In the exercises you resolve an ssh_config the way OpenSSH does, look up hashed known_hosts entries and compute key fingerprints; then you implement rsync's rolling-checksum algorithm and measure how many bytes it sends for different edits and block sizes.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

A secure telephone line to another computer

SSH lets you type commands on a computer that is far away, as if you were sitting at it, through a line nobody can listen in on. Instead of a password you usually use a key pair: a public key you can give to any computer you want to log into, and a private key that never leaves your laptop. The remote computer checks you hold the private key without ever seeing it. When copying files back and forth, a clever tool called rsync only sends the parts that changed.

rsync: send only what changed, even when data shifts
new file, as the sender encodes it:
# v2|t=0001 ax=+0.12 ay=-0.40 T=301.2|t=0002 ax=+0.10 ay=-0.38 T=301.4|t=0003 ax=+0.11 ay=-0.41 T=301.3|t=0004 ax=+0.09 ay=-0.39 T=301.6|
blue: copied from old blocks (8 copies) · orange: sent literally (9 bytes)
full copy
137 B
aligned blocks (no sliding)
171 B
rsync
73 B
Costs count 6 bytes of checksums per old block (a 4-byte rolling sum plus a truncated strong hash, whose length rsync chooses from the file size: 2 bytes for a file this small, with a whole-file checksum as the final guard), 1 byte per instruction, and 2 bytes per block for the aligned comparison. On a file of gigabytes a handful of changes costs a few kilobytes. Small blocks catch changes precisely but need many checksums; large blocks need few checksums but resend more around each change, so the best block size grows like the square root of the file size.
Why engineers care

Supercomputer jobs, cloud GPU training, a rover’s onboard computer during field tests and a ground-station server all sit behind SSH. Mission and research data move with rsync and scp. Knowing the config file, jump hosts and port forwarding turns a fragile chain of manual logins into one command.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Which key may you give away?
  2. 2. rsync is fast at updating a copy because it…
  3. 3. In the demo, why does inserting text at the start not force a full resend with rsync?

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Keys and first connection

ssh-keygen -t ed25519 -C "me@laptop"          # creates ~/.ssh/id_ed25519 (private) and .pub (public)
ssh-copy-id astro42@login1.hpc.example.edu    # appends the public key to the server's ~/.ssh/authorized_keys
ssh astro42@login1.hpc.example.edu            # log in; first time: verify the host key fingerprint!
ssh-add ~/.ssh/id_ed25519                     # unlock once per session with ssh-agent

Protect the private key with a passphrase and keep permissions strict (chmod 600, directory 700; ssh refuses keys that others can read). On first connection ssh shows the server’s key fingerprint; compare it with the one your administrator publishes, because accepting it blindly is how a man-in-the-middle gets in. Accepted keys are stored in ~/.ssh/known_hosts; a later mismatch produces the loud “REMOTE HOST IDENTIFICATION HAS CHANGED” warning.

Moving files

scp file host:dir/ (simple copy), sftp host (interactive), rsync -avz --progress src/ host:dst/ (incremental; the trailing slash on src/ means “contents of”). rsync --dry-run before --delete.

📝 Quick check (Level 1)
0/3 answered
  1. 1. Where on the server does your public key go?
  2. 2. The first-connection fingerprint prompt protects you from…
  3. 3. Which tool resumes and updates large transfers efficiently?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.

~/.ssh/config

Host cluster login*.hpc.example.edu
    HostName login1.hpc.example.edu
    User astro42
    IdentityFile ~/.ssh/id_ed25519_hpc

Host gpu?? !gpu99
    HostName %h.internal.hpc.example.edu
    ProxyJump cluster                    # hop through the login node
    LocalForward 8888 localhost:8888     # Jupyter on the compute node -> your laptop

Host *
    ServerAliveInterval 60
    IdentityFile ~/.ssh/id_ed25519

Rules: blocks are read top to bottom; for each option, the first value obtained wins; Host patterns use * and ?, and !pattern excludes. So put specific hosts first and Host * last. ssh -G host prints the resolved configuration.

Tunnels

  • Local forward -L 8888:localhost:8888: connections to port 8888 on your laptop go through SSH to port 8888 on the remote side (Jupyter, TensorBoard, a robot’s web UI).
  • Remote forward -R 9000:localhost:9000: the reverse direction.
  • Dynamic -D 1080: a SOCKS proxy.
  • ProxyJump -J bastion: reach internal machines through a gateway without storing keys on it (prefer it over agent forwarding, which lets the gateway’s admins use your agent).
🐍 Exercise 1: how OpenSSH reads its configuration and keys
Parse an ssh_config (Host blocks, patterns with * ? and !negation, Key value or Key=value), resolve the effective options for a host with first-value-wins semantics and %h expansion, build the ssh command line, look up plain and hashed (HMAC-SHA1) known_hosts entries including non-standard ports, and decode an ed25519 public key to compute its SHA256 and MD5 fingerprints.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Host * is the first block in a config and sets User a; a later Host box block sets User b. Connecting to box uses…
  2. 2. ssh -L 6006:localhost:6006 gpu07 lets you…
  3. 3. ssh -G host prints…

Level 3: Advanced

★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.

Remote development that survives

  • tmux (or screen) keeps your shell, training runs and editors alive when the connection drops: tmux new -s train, detach with Ctrl-b d, tmux attach -t train.
  • Remote IDEs: VS Code Remote-SSH and JetBrains Gateway run the language server on the remote machine and only the UI locally; Jupyter through a port forward.
  • Flaky links: ServerAliveInterval, connection multiplexing (ControlMaster auto, ControlPersist 10m) for many quick commands, mosh for roaming and high-latency connections.
  • Clusters: don’t compute on login nodes; request compute nodes from the scheduler (C5) and attach to them with ProxyJump.

Security essentials

Disable password authentication on servers you run, use keys with passphrases (or hardware keys: -t ed25519-sk), restrict authorized_keys entries (from=, command=), never copy private keys to shared machines, and verify host keys out of band (or with SSH certificates signed by a CA, which large sites use to avoid trust-on-first-use).

How rsync saves bandwidth

The receiver splits its old file into blocks of L bytes and sends a weak 32-bit rolling checksum and a strong hash of each. The sender slides a window over the new file: the weak checksum can be updated in O(1) per byte, a weak hit is confirmed with the strong hash, and matches become “copy block k” instructions. Data that merely moved (because of an insertion or deletion) is still found. Cost ≈ (N/L)·(checksum bytes) + (changes)·L, minimized near L ≈ √(checksum bytes · N / changes).

📝 Quick check (Level 3)
0/3 answered
  1. 1. Your 3-day training run must survive a laptop going to sleep. Use…
  2. 2. rsync's weak checksum must be…
  3. 3. Agent forwarding to a shared server risks…

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

SSH and rsync, measured

Exercise 1. For the configuration above, cluster resolves to login1 with user astro42 and the HPC key (the earlier block wins over Host *) while still picking up ServerAliveInterval 60 from Host *; gpu07 becomes ssh -i ~/.ssh/id_ed25519 -J cluster -L 8888:localhost:8888 astro42@gpu07.internal.hpc.example.edu; gpu99 is excluded by !gpu99; rover gets -p 2222 and user ubuntu. Hashed known_hosts entries are found by recomputing HMAC-SHA1 with each entry’s salt (and [host]:port for non-standard ports). An ed25519 key blob is 51 bytes and its SHA256 fingerprint is 43 base64 characters.

Exercise 2: the rsync algorithm. A 144 000-byte telemetry CSV, block size 1024, 20 bytes of checksums per block, 5 bytes per instruction:

Edit full copy aligned blocks rsync
change 10 bytes in the middle 144 000 3 985 5 189
insert 100 bytes at the start 144 100 147 345 4 270
append 2 KB 146 048 6 043 6 213
5 scattered 1-byte changes 144 000 8 081 9 285

Without a sliding search, an insertion makes every following block differ and the “diff” costs more than the file; rsync sends 34× less than a full copy. Where nothing shifts, aligned comparison is slightly cheaper (16 instead of 20 checksum bytes per block). Block-size sweep for the 5-change edit: 56 570 B at L = 64, 9 738 at 512, 9 285 at 1024, 12 655 at 2048, 46 146 at 8192, matching the predicted optimum √(20·144000/5) ≈ 759 within the factor-of-two grid. (Real rsync also run-length-codes consecutive copies and compresses literals.)

🐍 Exercise 2 (research): the rsync algorithm
Implement rsync's weak rolling checksum with O(1) updates, the receiver's block signature (weak + MD5), the sender's sliding delta, and patching; check that patching reproduces the new file. Compare bytes sent by a full copy, an aligned-block comparison and rsync for four kinds of edits, sweep the block size, and compare with the square-root rule.

SSH in AI, robotics and aerospace

  • HPC and cloud: login through bastions with ProxyJump, Jupyter and TensorBoard through local forwards, datasets synchronized with rsync.
  • Robots in the field: SSH over Wi-Fi or a tether to onboard computers; tmux keeps ROS nodes running when the link drops.
  • Ground stations: automated, key-restricted rsync jobs pull telemetry from antenna sites; checksums verify integrity.
  • Fleets: SSH certificates from a CA instead of per-machine known_hosts management.

References

  1. T. Ylonen, C. Lonvick (2006). The Secure Shell (SSH) Protocol Architecture, RFC 4251; Transport Layer Protocol, RFC 4253.
  2. OpenSSH manual pages: ssh(1), ssh_config(5), sshd(8), ssh-keygen(1) (man.openbsd.org).
  3. A. Tridgell, P. Mackerras (1996). “The rsync algorithm.” Technical Report TR-CS-96-05, Australian National University.
  4. A. Tridgell (1999). Efficient Algorithms for Sorting and Synchronization. PhD thesis, Australian National University.
  5. D. J. Barrett, R. E. Silverman, R. G. Byrnes (2005). SSH, The Secure Shell: The Definitive Guide, 2nd ed. O’Reilly.