Created
January 27, 2019 23:33
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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