Перейти к содержимому

Open a cloud host's files on your Mac from herdr

Это содержимое пока не доступно на вашем языке.

You run herdr on your Mac and connect it to a cloud host over SSH, so your agents work in a big, always-on Linux machine. Sooner or later one of them writes report.pdf, results.xlsx, deck.pptx or demo.mp4, and you want to look at it. A terminal cannot show a slide deck, and copying the file with scp means leaving herdr, remembering the path and typing the host name.

herdr-open (MIT, Go) closes that gap. On the host you pick a file; a moment later it opens on your Mac in the app you would use for it locally. This post shows the setup we use on two Linux hosts and one Mac, and two pitfalls we hit along the way.

your Mac
┌───────────────────────────────────┐
│ herdr-open serve (launchd) │
│ ~/.herdr-open/herdr-open.sock │
│ → ~/Downloads/herdr-open/<host>/ │
│ → open in the default app │
└─────────────────▲─────────────────┘
│ SSH RemoteForward
┌─────────────────┴─────────────────┐
│ ~/.herdr-open/herdr-open.sock │
│ herdr-open send FILE │
│ (shell, herdr popup, yazi key M) │
└───────────────────────────────────┘
cloud host (devbox)
  • herdr-open serve runs on the Mac and listens on a unix socket, ~/.herdr-open/herdr-open.sock.
  • An SSH RemoteForward makes that socket appear on the host at the same place under your remote home directory.
  • On the host, herdr-open send FILE writes the file into the socket. The Mac saves it and opens it.

No port is opened on either side, there is no file server and no extra login. Only your user on the host (and root) can reach the socket, and only while the forward is connected.

The Mac saves every file to ~/Downloads/herdr-open/<remote hostname>/. What happens next depends on the type:

Type Extensions What happens
Documents .pdf .txt .md .log .csv .json .yaml .toml .diff .rtf Opened in the default app
Office .docx .xlsx .pptx .pages .numbers .key Opened in Word, Excel, PowerPoint, Pages, Numbers or Keynote
Images .png .jpg .gif .webp .heic .tiff .bmp Opened in Preview (or your default viewer)
Video and audio .mp4 .mov .m4v .mp3 .m4a .wav .aac .flac Opened in QuickTime (or your default player)
Everything else scripts, .command, .py, installers, archives, HTML, SVG, unknown types Only shown in Finder, never opened

That last row is deliberate. A host you work on could be compromised, so the Mac treats what it receives the way a browser treats a download:

  • Only an allowlist of documents and media is opened. Anything that could run code is revealed in Finder for you to decide.
  • File names are cleaned: path components are dropped, and invisible and bidirectional characters are replaced. A name that used U+202E (right-to-left override) to make exe look like txt arrived as a_txt.exe.
  • A file with the same name as an earlier one is saved as name (1).ext; nothing is overwritten.
  • Every file gets the macOS quarantine flag, so Gatekeeper asks before anything in it runs.
  • Files are saved with mode 600 and directories with 700. Files over 512 MiB are refused by default.

Install the binary (Apple silicon shown; use herdr-open-darwin-amd64 on Intel), check it against the release’s SHA256SUMS, and start the service:

Terminal window
mkdir -p ~/.local/bin
curl -fsSLO https://github.com/hmob-app/herdr-open/releases/latest/download/herdr-open-darwin-arm64
curl -fsSLO https://github.com/hmob-app/herdr-open/releases/latest/download/SHA256SUMS
shasum -a 256 -c --ignore-missing SHA256SUMS
install -m 755 herdr-open-darwin-arm64 ~/.local/bin/herdr-open
herdr-open service install # launchd agent, starts at login; log in ~/Library/Logs/herdr-open.log

As the user who runs herdr:

Terminal window
mkdir -m 700 -p ~/.herdr-open # sshd creates the socket, not its directory
herdr plugin install hmob-app/herdr-open # the herdr popup and doctor actions
# herdr-open on PATH, for the shell and yazi
cd "$(mktemp -d)" && a=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
curl -fsSLO "https://github.com/hmob-app/herdr-open/releases/latest/download/herdr-open-linux-$a"
curl -fsSLO https://github.com/hmob-app/herdr-open/releases/latest/download/SHA256SUMS
sha256sum -c --ignore-missing SHA256SUMS && install -m 755 "herdr-open-linux-$a" ~/.local/bin/herdr-open

When an SSH connection drops, sshd leaves the socket file behind, and by default the next connection cannot forward over it. Tell sshd to replace it (once per host, as root):

Terminal window
echo 'StreamLocalBindUnlink yes' | sudo tee /etc/ssh/sshd_config.d/50-herdr-open.conf
sudo sshd -t && sudo systemctl reload ssh # or: sudo systemctl reload sshd

Forward the socket: use a dedicated connection

Section titled “Forward the socket: use a dedicated connection”

This is the first pitfall. herdr starts ssh with -F pointing at a temporary config that Includes your ~/.ssh/config, so a RemoteForward line in the host’s Host block does ride herdr’s own connection. It looks like the obvious place for it. Don’t put it there.

With StreamLocalBindUnlink yes, every new SSH connection to that host that carries the same RemoteForward replaces the socket. Run ssh devbox, scp or git pull from the Mac once, and when that command exits it takes the socket with it: herdr-open send gets “connection refused” until herdr reconnects.

Instead, give each host one connection that only forwards the socket. autossh (brew install autossh) restarts it when it drops; a plain ssh -N that we tried first stopped after a network drop and did not come back.

Terminal window
autossh -M 0 -N \
-o ExitOnForwardFailure=yes \
-o ServerAliveInterval=15 \
-o ControlMaster=no -o ControlPath=none \
-R /home/ubuntu/.herdr-open/herdr-open.sock:/Users/you/.herdr-open/herdr-open.sock \
devbox
  • ExitOnForwardFailure=yes makes ssh exit (and autossh retry) if the forward cannot be set up, instead of sitting connected without it.
  • ServerAliveInterval=15 notices a dead network within about a minute.
  • ControlMaster=no and ControlPath=none keep this connection out of any multiplexed master you use for other sessions.
  • Both socket paths must be absolute. Remove any RemoteForward for the socket from the host’s Host block in ~/.ssh/config.

It works through a ProxyCommand too; we use it with an AWS Systems Manager (SSM) ProxyCommand on hosts that have no public SSH port.

Keep it running with launchd. Save this as ~/Library/LaunchAgents/local.herdr-open-forward.devbox.plist, one file per host:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>local.herdr-open-forward.devbox</string>
<key>ProgramArguments</key>
<array>
<string>/opt/homebrew/bin/autossh</string>
<string>-M</string><string>0</string>
<string>-N</string>
<string>-o</string><string>ExitOnForwardFailure=yes</string>
<string>-o</string><string>ServerAliveInterval=15</string>
<string>-o</string><string>ControlMaster=no</string>
<string>-o</string><string>ControlPath=none</string>
<string>-R</string>
<string>/home/ubuntu/.herdr-open/herdr-open.sock:/Users/you/.herdr-open/herdr-open.sock</string>
<string>devbox</string>
</array>
<key>EnvironmentVariables</key>
<dict>
<!-- autossh retries even when the first attempt fails at once -->
<key>AUTOSSH_GATETIME</key><string>0</string>
<!-- launchd's PATH is minimal; a ProxyCommand may need tools from Homebrew -->
<key>PATH</key><string>/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
<key>RunAtLoad</key><true/>
<key>KeepAlive</key><true/>
</dict>
</plist>
Terminal window
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/local.herdr-open-forward.devbox.plist

The connection runs without a terminal, so your SSH key must work without a prompt (from the macOS keychain or ssh-agent).

Then check from the host:

Terminal window
herdr-open doctor

On the host there are three ways:

How What
herdr-open send report.pdf Save and open on the Mac. --reveal shows it in Finder instead; --save only saves it.
herdr action herdr-open: open a file on my computer A popup that asks for a path, relative to the focused pane. Tab completes.
yazi with herdr-yazi, key M Sends the hovered or selected files. Add the keymap entry to ~/.config/yazi/keymap.toml.

The yazi route is the one we use most: browse the agent’s output directory, select a few files, press M. To read a Markdown file or a diff without leaving the terminal, herdr-file-viewer renders it in place (with glow and delta). It is view-only and cannot send files to the Mac.

This is the second pitfall. herdr custom keybindings of type = "plugin_action" are read from the config of the herdr server that runs the panes, not from the client you type into. When the panes run on the host, bindings in your Mac’s ~/.config/herdr/config.toml only fire in your Local session, and there herdr answers “plugin action not found”, because the plugins live on the host.

Put them in the host’s ~/.config/herdr/config.toml. prefix+o is already herdr’s default for open_notification_target, so we use prefix+alt+<key>:

[[keys.command]]
key = "prefix+alt+o"
type = "plugin_action"
command = "hmob-app.herdr-open.send"
description = "herdr-open: open a remote file on this computer"
[[keys.command]]
key = "prefix+alt+d"
type = "plugin_action"
command = "hmob-app.herdr-open.doctor"
description = "herdr-open: check the connection"
# herdr-yazi registers its plugin id as ray.file-explorer.
[[keys.command]]
key = "prefix+alt+e"
type = "plugin_action"
command = "ray.file-explorer.open"
description = "yazi file explorer (M sends to this computer)"
[[keys.command]]
key = "prefix+alt+f"
type = "plugin_action"
command = "herdr-file-viewer.open-file-viewer"
description = "file viewer (read-only)"

On macOS your terminal must send Option as Alt for these to reach herdr. In Ghostty, set macos-option-as-alt = true.

  • herdr-open doctor cannot connect. Check that the forward is running on the Mac (launchctl print gui/$(id -u)/local.herdr-open-forward.devbox), that ~/.herdr-open exists on the host with mode 700, and that StreamLocalBindUnlink yes is active (sudo sshd -T | grep -i streamlocalbindunlink).
  • It worked, then stopped after you used ssh or scp. A RemoteForward for the socket is still in a Host block of your ~/.ssh/config. Remove it and rely on the dedicated connection.
  • A key does nothing, or says “plugin action not found”. The binding is in the Mac’s herdr config instead of the host’s, or the terminal is not sending Option as Alt.
  • The file was saved but not opened. Its type is not on the allowlist. Look in ~/Downloads/herdr-open/<remote hostname>/ in Finder.

herdr-open is for when you sit at your Mac. When you step away, Hmob is an iPhone and iPad app for the same herdr sessions, talking to a small gateway you host yourself, so you can keep an eye on your agents and answer them from your phone.