Copy file contents or command output to your clipboard over SSH via OSC 52 — no daemons, no port forwarding, no nonsense.
OSC 52 is a terminal escape sequence that instructs your terminal emulator to place data into the system clipboard. This works over SSH without any additional tools, daemons, or port forwarding — the terminal receives the escape sequence and handles the clipboard access locally on your machine.
Your terminal emulator must support OSC 52. Standard PuTTY does not support it. ❌
Recommended alternatives:
- 🪟 KiTTY — a PuTTY fork with OSC 52 support (Windows)
- 🚀 Alacritty — cross-platform, OSC 52 enabled by default
- 🌊 WezTerm — cross-platform, OSC 52 enabled by default
- 🍎 iTerm2 — macOS, OSC 52 enabled by default
- 🐧 foot — Linux/Wayland
curl -O https://raw.githubusercontent.com/rguziy/2clip/master/2clip.sh
chmod +x 2clip.sh
sudo mv 2clip.sh /usr/local/bin/2clipOr clone the repo:
git clone https://github.com/rguziy/2clip.git
chmod +x 2clip/2clip.sh
sudo ln -s "$PWD/2clip/2clip.sh" /usr/local/bin/2clip📄 Copy a file:
2clip file.txt🔗 Copy command output (pipe / stdin):
ls -la | 2clip
cat /etc/hosts | 2clip
grep "error" app.log | 2clip⚡ Copy command output (inline via -c):
2clip -c "ps aux | grep nginx"
2clip -c "cat file.txt | sort | uniq"tmux intercepts terminal escape sequences by default, which breaks OSC 52 passthrough. Add the following to your ~/.tmux.conf:
# Use 256-color terminal
set -g default-terminal "screen-256color"
# Enable true color and OSC 52 clipboard passthrough
set -as terminal-overrides ',xterm-256color:Tc:Ms'
set -s set-clipboard onAfter editing, reload the config:
tmux source-file ~/.tmux.confIf you use tmux copy mode, you can bind y to copy the selection to clipboard:
# Use vi-style keybindings in copy mode
setw -g mode-keys vi
# Press 'y' in copy mode to copy selection and exit
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel