This document explains the SSH clipboard configuration for seamless copy/paste across SSH sessions using OSC 52 escape sequences.
- Local Machine: Arch Linux with Ghostty terminal and Wayland
- Remote Connections: SSH to Ubuntu servers
- Remote Access: Mac connects via Tailscale (not traditional SSH)
Added clipboard passthrough to allow OSC 52 sequences to work through tmux:
set -g set-clipboard on
set -ag terminal-overrides "vte*:XT:Ms=\\E]52;c;%p2%s\\7"
set -ag terminal-overrides "xterm*:XT:Ms=\\E]52;c;%p2%s\\7"
set -ag terminal-overrides "xterm-ghostty:XT:Ms=\\E]52;c;%p2%s\\7"Created easy-to-use clipboard commands that work over SSH:
| Command | Usage | Description |
|---|---|---|
clip |
echo "text" | clip |
Copy to clipboard via OSC 52 (works over SSH) |
clipfile <file> |
clipfile script.sh |
Copy entire file contents |
copy |
echo "text" | copy |
Copy to Wayland clipboard (local only) |
paste |
paste |
Paste from Wayland clipboard (local only) |
Configured SSH to preserve terminal capabilities and keep connections alive:
Host *
SetEnv TERM=xterm-256color
ServerAliveInterval 60
ServerAliveCountMax 3
ForwardAgent yes
AddKeysToAgent yes
Enabled clipboard support explicitly:
copy-on-select=false
clipboard-read=allow
clipboard-write=allow
clipboard-paste-protection=false
- SSH config is now tracked in your dotfiles repo
- Private keys are excluded via
.ssh/.gitignore - Permissions are automatically fixed by
link.sh(700 for dir, 600 for files)
Remote Server → OSC 52 Sequence → SSH Connection → Tmux → Ghostty → Wayland Clipboard
OSC 52 Escape Sequence Format:
\033]52;c;<base64-encoded-text>\a
This escape sequence travels through:
- Your shell on the remote server
- The SSH connection (as terminal output)
- Tmux (if running) - passes it through
- Ghostty terminal - intercepts and puts text in clipboard
- Wayland clipboard system - now you can paste anywhere
On a remote Ubuntu server:
# Copy command output
ls -la | clip
# Copy a file's contents
clipfile ~/.bashrc
# Copy some text
echo "Hello from remote server" | clipBack on your local machine:
# Paste with Ctrl+V or:
wl-paste
# Or use the Fish function:
pasteecho "test local" | clip
wl-paste # Should output: test localssh your-ubuntu-server
echo "test remote" | clip
# Exit SSH, then on local machine:
wl-paste # Should output: test remotetmux
echo "test tmux" | clip
# Detach (Ctrl+b d) and paste - should work-
Check TERM variable on remote:
echo $TERM # Should be xterm-256color
-
Test OSC 52 directly:
printf "\033]52;c;%s\a" $(echo "test" | base64)
-
Check tmux passthrough:
tmux show-options -g | grep clipboard # Should show: set-clipboard on
Solutions:
-
Use keyboard shortcut:
Ctrl+L(works in any shell) -
Install ncurses on remote:
sudo apt install ncurses-bin
-
Create alias on remote:
# Add to remote ~/.bashrc or ~/.config/fish/config.fish alias clear='printf "\033c"'
The link.sh script has been rewritten to be much safer:
Before (DANGEROUS):
stow -D(unstow everything) → Configs disappear!stow(try to restow) → If this fails, you have no configs
Now (SAFE):
- Remove known auto-generated files (like Hyprland defaults)
- Run dry-run to check for conflicts
- Prompt before continuing if conflicts exist
- Use
stow --restow(never removes configs unless replacing) - Fix permissions and reload services
- No unstowing - configs never disappear
- Dry-run first - checks for problems before making changes
- Auto-handles known programs that create default configs
- Interactive - prompts you if there are conflicts
- Safe to run repeatedly - idempotent, won't break things
Just run:
./link.sh
# or
dots_linkIf a program created a file where your symlink should go:
- The script will detect it and prompt you
- Either manually remove the file, or
- Add it to the "auto-generated files" section in
link.sh
| File | Changes |
|---|---|
.tmux/.tmux.conf |
Added OSC 52 clipboard support |
.config/fish/functions/clipboard.fish |
Created (new file with clipboard functions) |
.ssh/config |
Created in dotfiles with SSH client settings |
.ssh/.gitignore |
Created (excludes private keys from git) |
.config/ghostty/config |
Added explicit clipboard settings |
link.sh |
Completely rewritten for safety |