PhD Lunch Presentation

‘Optimal’ Server Workflow

Author

Jonas Skjold Raaschou-Pedersen

Published

November 25, 2025

TOC

‘Optimal’ Server Workflow

Ez VPN

How I quickly connect

#!/bin/bash

pass kup | sudo openconnect vpn.ku.dk --user="$(pass kua)" --passwd-on-stdin
  • I have saved this script as vpnku in folder /home/jsr-p/scripts that is in my PATH (variable)
  • Hence I can simply type vpnku, feel my phone vibrate in the pocket, accept and be on the KU network
  • Ez

Stuff to read up on:

Sshpass easy connect to server

  • I use a ssh alias for the sodas server, sodashead

  • Inside ~/.ssh/config:

Host sodashead
  HostName sodashead01fl.unicph.domain
  User <KU-USER>
  LocalForward 8888:127.0.0.1 8888 
  IdentityFile ~/.ssh/id_ed25519
  SetEnv TERM=xterm-256color
  IdentitiesOnly yes
  • See the sodas docs for details on:
    • Port-forwarding (the 8888:127.0.0.1 8888 line)
    • ssh keys (the ~/.ssh/id_ed25519 line)
  • With the ssh alias I can type ssh sodashead to connect to the server instead of ssh sodashead01fl.unicph.domain
  • I don’t want to type the password all the time when using ssh and friends
  • Hence I use the sshpass command-line utility to provide my password to the ssh command non-interactively
#!/usr/bin/env bash
SSHPASS=$(pass kup) sshpass -e ssh sodashead
  • Save the script as sodashead on my computer
  • Typing sodashead executes the script, and if connected to vpn, yields a nice hello message from KU IT :=)

Use tmux

  • Want to be able to have multiple terminals sessions on the server
  • tmux, the great terminal multiplexer, allows us to do exactly this
  • Read the manual page for the keybindings
    • Spltting panes, <prefix>+:

      "           Split the current pane into two, top and bottom.
      %           Split the current pane into two, left and right.
  • One plugin for tmux I recommend is tmux-pain-control
    • Allows us to split panes with:
      • <prefix>+| - split into left and right
      • <prefix>+- - split into top and bottom
    • More intuitive :)

Use git

lazygit

  • A nice TUI for using git
  • We can download a release from github
    • Then unpack it with tar
    • Move the binary to ~/.local/bin which should be in your PATH
      • If not:

         # Paste this to your: ~/.bashrc
         export PATH="$HOME/.local/bin:$HOME/bin:$PATH"

mkdir -p ~/downloads
cd ~/downloads
wget https://github.com/jesseduffield/lazygit/releases/download/v0.56.0/lazygit_0.56.0_linux_x86_64.tar.gz
tar xvf lazygit_0.56.0_linux_x86_64.tar.gz
mv lazygit ~/.local/bin/

Shell alias

  • Tedious to type out long commands all the time

  • Example aliases:

    alias c="clear"
    alias e="exit"
    alias senv="source .venv/bin/activate"

Share files over ssh with scp

  • Export SSHPASS in your local shell
  • E.g.:
export SSHPASS=$(pass kup)

Copy local file to server

# syntax: sscp local-file host-alias:remote-folder
sshpass -e scp workflow.html sodashead:/home/abc123/phd-lunch

or

alias sscp="sshpass -e scp"
sscp workflow.html sodashead:/home/abc123/phd-lunch

Copy file from server to local

Using alias from above:

# syntax: sscp host-alias:remote-file local-folder
sscp sodashead:/home/abc123/phd-lunch/research-secrets/phone-numbers-nature-editors.txt .

Share folder over ssh with rsync

Sync remote to local

alias rsdir="sshpass -e rsync -av"
# or: rsdir sodashead:phd-lunch/research-secrets .
rsdir sodashead:/home/abc123/phd-lunch/research-secrets .

Sync local to remote

rsdir scripts-research sodashead:phd-lunch

Shell history with fzf

  • fzf — 🫡
  • Taken from my ~/.bashrc config file
# Bind to Ctrl+r, Ctrl+j, Ctrl+k
bind -x '"\C-r": fzf_select_command'

export FZF_DEFAULT_OPTS='-i --height=50% --layout reverse'
export FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --bind=ctrl-j:down,ctrl-k:up"

# Define the fzf_select_command function
fzf_select_command() {
  local selected_command
  selected_command=$(tac ~/.bash_history | awk '!seen[$0]++' | fzf)
  if [ -n "$selected_command" ]; then
    READLINE_LINE="${READLINE_LINE}${selected_command}"
    READLINE_POINT=${#READLINE_LINE}
  fi
}
  • Exercise:
    1. Download a fzf binary from the github release page
    2. Unpack it with tar
    3. Move it to your ~/.local/bin
    4. Ascend with fzf

Slurm

uv

  • For Python scripts I only use uv
  • For installation instructions, see sodas docs

srun

Allocate an interactive shell on the server with:

srun -w sodasgpun01fl --ntasks-per-node=2 --mem=5GB --time=240 --pty /bin/bash -i

Running script from synced folder

 ls -1 scripts-research
decision_tree_example.py
dml_example_ate.py

Hence on server:

uv run decision_tree_example.py

This creates two figures inside the scripts-research/figs-folder on the server.

Sync output back
rsdir sodashead:phd-lunch/scripts-research .

Hence locally:

 ls -1 scripts-research/figs
iris_dt2.png
iris_dt.png

Jupyter

uv run jupyter-lab --port 8880 --ip=10.84.10.216 --no-browser

Using R or other things on server

Ucloud

Further ressources

Below are some miscellaneous links that you might find useful.

Command line

If you want to learn more about the command line see e.g.:

Git

Tips for Windows users

If you are a Windows users see Grant McDermott’s (Principal Economist at Amazon) slides here for two ways to get the Unix shell (which is what Mac and Linux users have by default) on Windows. Try following Grant McDermott’s advice in his slides and install WSL.

If you feel even more adventurous you can try installing a Linux distribution. This is the proper way to get the full Unix experience. For instance, you can try dual-booting Ubuntu or go directly to this (don’t hesitate to ask me for details if you are interested); you won’t regret it.