PhD Lunch Presentation
‘Optimal’ Server Workflow
TOC
‘Optimal’ Server Workflow
- ‘Optimal’ for me (until I get more enlightened)
- Many roads lead to Rome
- We have a website https://cph-sodas.github.io/ with different guides for e.g.
- Access
- Setup
- Usage
- Misc. tips
Ez VPN
- I use OpenConnect
- Does the same things as the Cisco GUI — you can use Cisco if you like
- Works on MacOS and Linux
- Windows users, consider using Windows Subsystem for Linux (WSL) when interacting with the server (and terminal in general)
- See also Tips for Windows users
How I quickly connect
- I use the the standard unix password manager to store my KU user and password
- User stored as
kua; password askup
- User stored as
- Typing
pass kuayields my user to stdout - I can pipe my password into the vpn command and provide the user through command substitution
#!/bin/bash
pass kup | sudo openconnect vpn.ku.dk --user="$(pass kua)" --passwd-on-stdin- I have saved this script as
vpnkuin folder/home/jsr-p/scriptsthat 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,
sodasheadInside
~/.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 8888line) - ssh keys (the
~/.ssh/id_ed25519line)
- Port-forwarding (the
- With the ssh alias I can type
ssh sodasheadto connect to the server instead ofssh sodashead01fl.unicph.domain - I don’t want to type the password all the time when using
sshand friends - Hence I use the sshpass command-line utility to provide my password to the
sshcommand non-interactively
#!/usr/bin/env bash
SSHPASS=$(pass kup) sshpass -e ssh sodashead- Save the script as
sodasheadon my computer - Typing
sodasheadexecutes 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 :)
- Allows us to split panes with:
Use git
- God gave us life — Linus Thorvalds gave us Linux and Git 🙏
- 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/binwhich should be in yourPATHIf not:
# Paste this to your: ~/.bashrc export PATH="$HOME/.local/bin:$HOME/bin:$PATH"
- Then unpack it with
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"
Shell history with fzf
- fzf — 🫡
- Taken from my
~/.bashrcconfig 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:
- Download a
fzfbinary from the github release page - Unpack it with
tar - Move it to your
~/.local/bin - Ascend with
fzf
- Download a
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 -iRunning script from synced folder
❯ ls -1 scripts-research
decision_tree_example.py
dml_example_ate.pyHence on server:
uv run decision_tree_example.pyThis 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.pngJupyter
uv run jupyter-lab --port 8880 --ip=10.84.10.216 --no-browserUsing R or other things on server
- See the sodas docs
Ucloud
- See the sodas docs
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.