Shared remote clipboard with SSH

San Francisco bridge by Bernard
San Francisco bridge by Bernard

SUMMARY Working remotely using SSH? And wanting a shared clipboard with the host you are working on? Or show a notification on the host, from a remote script? sshboard has you covered.

2025-01-02 ssh clipboard remote

sshboard is a tool to interact with your desktop environment from a remote SSH sessions: share clipboard contents, open URLs and show notifications on your desktop. This way, your remote neovim session can paste directly from your clipboard, and yanking in a remote session will end up in your local clipboard manager (e.g. clipmenu). sshboard uses the SSH connection (specifically UNIX domain socket forwarding), so the clipboard contents are encrypted during transmission.

sshboard uses the SSH connection (specifically UNIX domain socket forwarding), so the clipboard contents are encrypted during transmission. Because it uses private UNIX domain sockets, instead of open port forwards like lemonade, the security on shared servers is improved as only the current user can share the link to the desktop.

If no remote session is found, the local clipboard is used. There is some custom support to handle tmux sessions, so that reconnecting to a tmux session won't break your clipboard interactions.

Integrates with:

Installation instructions can be found here.

How does it work?

If you want to simulate this for yourself, you can run ssh -R /tmp/clipboardclient:/tmp/clipboardserver host. Tests can be done with nc -lU /tmp/clipboardserver (on the remote) and nc -U /tmp/clipboardclient (on the client).

A problem is that if the /tmp/clipboardclient already exists (after an old session), the proxy of the port won't work. -o 'StreamLocalBindUnlink=yes' is supposed to help, however, at least for -R mode, it does not. See this bugreport. It works if StreamLocalBindUnlink yes is specified in the server config.

For custom neovim clipboards, see :help g:clipboard how the can be set up.

Daemon on host

Now we have a communication channel. This should be randomized and user specific in order to work on systems with multiple users. But we now also want to perform actions. For this we need a daemon running on the host. Every time a remote client connects to the socket, a connection is created. Once connected, the UNIX domain socket is moved to a temporary location, e.g. /tmp/clipboardserver.32235, and a new fresh UNIX domain socket is created at /tmp/clipboardserver.

Using a binary protocol, the daemon waits on commands. Such commands can be get (read) the clipboard, set (write) the clipboard, show a notification, or open a link.

To make starting a session easier sshboard supports the sshboard ssh wrap command, that automatically starts a session with the right UNIX domain forward, and start the daemon if it was not running yet.

WSL support

Depending on the host the daemon runs on, it detects which desktop environment is used. It can even detect Windows, and integrates with the Windows clipboard using the Linux WSL Windows interop features.

More features wanted?

More things can be supported, like local command execution started from a remote host, or copying files.

Let me know what you think and if you have opinions on how to progress.