Skip to content

Instantly share code, notes, and snippets.

@schuerg
Created January 27, 2019 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schuerg/2853aa90a6dabf69df34728b82c9ec0a to your computer and use it in GitHub Desktop.
Save schuerg/2853aa90a6dabf69df34728b82c9ec0a to your computer and use it in GitHub Desktop.
[Use local clipboard over SSH] Forward local clipboard over SSH using socat #linux #clipboard #ssh #socat #networking
[Unit]
Description=Daemon for copying to (a remote) clipboard over a TCP socket
After=graphical-session.target
StartLimitBurst=5
[Service]
; %h gets expanded to the current user's home dir
; See https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Specifiers
ExecStart=%h/.local/bin/socopy-daemon
Type=simple
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=default.target
#!/usr/bin/env bash
# Simple daemon which listens for TCP connections and
# redirects messages to the local system clipboard.
#
# This works perfectly fine to forward the local
# system clipboard to remote SSH sessions.
#
# Simon Schürg
set -e
set -o pipefail
if ! [ -x "$(command -v socat)" ]; then
echo 'Error: socat is not installed.' >&2
exit 1
fi
if ! [ -x "$(command -v xsel)" ]; then
echo 'Error: xsel is not installed.' >&2
exit 1
fi
# let this script crash if xsel is not working
xsel > /dev/null
socat -v TCP-LISTEN:5556,fork,bind=localhost EXEC:"xsel --clipboard --input"
[Unit]
Description=Daemon for pasting from (a remote) clipboard over a TCP socket
After=graphical-session.target
StartLimitBurst=5
[Service]
; %h gets expanded to the current user's home dir
; See https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Specifiers
ExecStart=%h/.local/bin/sopaste-daemon
Type=simple
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=default.target
#!/usr/bin/env bash
# Simple daemon which listens for TCP connections and
# redirects messages to the local system clipboard.
#
# This works perfectly fine to forward the local
# system clipboard to remote SSH sessions.
#
# Simon Schürg
set -e
set -o pipefail
if ! [ -x "$(command -v socat)" ]; then
echo 'Error: socat is not installed.' >&2
exit 1
fi
if ! [ -x "$(command -v xsel)" ]; then
echo 'Error: xsel is not installed.' >&2
exit 1
fi
# let this script crash if xsel is not working
xsel > /dev/null
socat -v TCP-LISTEN:5557,fork,bind=localhost EXEC:"xsel --clipboard"
Host example.com
# Forwarding for socopy/sopaste (soclip)
RemoteForward 5556 localhost:5556
RemoteForward 5557 localhost:5557
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment