How phux uses your own ssh (config, jump hosts, keys) to add a machine, attach without pairing, and forward ports and your ssh-agent.
Signing in once
From a terminal, phux logs in to a host once, so a password, 2FA, or
security-key prompt appears a single time and later steps reuse the login.
It keeps that login as its own ssh connection in /tmp/phux-ssh-<uid>
(owner-only) until five minutes after last use; your own ControlMaster and
LocalForward settings are not touched. Rune asks in a dialog instead (on
Linux, through SSH_ASKPASS). From a script phux never prompts, so the host
needs a key that works alone. With BatchMode yes in your config, ssh can’t
ask for a password, so neither can phux; the error says so.
Logins turned away by sshd’s MaxStartups are retried a few times; a
refused password, key, or host key never is. Past MaxSessions, ssh logs
the extra connection in on its own, which asks again on a password host.
When ssh fails with little explanation, phux prints the same ssh command
with -v to copy.
When the host key changes
phux stops and prints the ssh-keygen -R command that removes the old key.
A reinstall changes it, and so does someone intercepting the connection:
confirm the new key with whoever runs the host first. phux never removes or
accepts a key for you.
Keys in an agent
phux’s ssh finds your agent through IdentityAgent in ~/.ssh/config, or
the inherited SSH_AUTH_SOCK. An app opened from the Dock has no
SSH_AUTH_SOCK, so in Rune a key held only in an agent (1Password,
Secretive) fails with Permission denied (publickey). Either fixes it, and
IdentityAgent wins:
# ~/.ssh/config
Host *
IdentityAgent ~/.1password/agent.sock
# config.toml
[rune]
ssh-agent = "~/.1password/agent.sock"
Keys in hardware
Two keys reach a machine: your ssh key (use an sk- key or a hardware agent
to keep it in hardware), and the key behind the client certificate
phux host add enrolls. On a Mac with a Secure Enclave, --hardware-key
keeps the certificate’s key in the enclave:
phux host add me@mini --hardware-key
phux host add mini --code LINK --hardware-key
phux host renew mini --hardware-key # move an existing file key
The key never leaves the chip, and the key file holds only a reference this
Mac’s enclave can use. A copied key file signs nothing elsewhere. It does
not protect against a program running as you on this Mac, which can ask the
enclave to sign without a prompt. Renewal keeps the old key until the server
accepts the new certificate. phux host ls shows hardware or file. On a
machine without an enclave the flag is refused and nothing changes.
Attaching over SSH
phux attach --ssh me@box
SSH logs you in, starts the remote server if needed, and opens a QUIC
listener for this attach alone; then SSH exits and the session runs over
QUIC, so it survives network changes. The listener and its token live only
in memory and go away shortly after you detach. --udp-ports 60000-61000
keeps the listener in a range one firewall rule can cover.
The remote server opens that listener only in paired mode, and admits only
a client certificate it enrolled. If it refuses, or UDP can’t get through, phux
says why and carries the session through
ssh itself. That does not roam: on a network drop phux logs in again and
re-attaches. phux remembers a host whose UDP didn’t answer for a day
(udp-unanswered in the state directory) and keeps probing UDP in the
background. An SSH login failure, or a host without phux, is an error, not a
fallback.
Forwarding a port
phux forward -L 3000:localhost:3000 --remote mini
Like ssh -L, through the phux connection: listens on 127.0.0.1:3000 here
and carries each connection to localhost:3000 on mini, until Ctrl-C.
-L 3000 alone means the same. Repeat -L to forward more than one port; if
any can’t listen, none does. If
the phux connection drops, open connections close, the listener stays, and
new connections are served once phux reconnects; a cut-off transfer ends
early rather than with an error. There is no -D or UDP, and a forward does
not reach a linked machine behind the server.
phux forward @3 --remote mini # every port pane @3 listens on
phux forward @3:5173 --remote mini # only that one
A pane’s ports come from what the server sees it
listen on: each one bound to
loopback or to every address, on the same port here when it is free, else
another, as the printed line says. They are read once, when the run starts:
a port the pane opens later needs another phux forward @N.
phux forward -R 8080:localhost:3000 --remote mini
The reverse, like ssh -R: the server on mini listens on its own
127.0.0.1:8080 and carries each connection there to localhost:3000 on
this machine. A leading localhost: listens on both loopback families and
[::1]: on IPv6 only; the server never listens beyond its loopback, and
never on a port another program there holds. When localhost: can take only
127.0.0.1, the run says so. Port 0 lets the server pick, and the printed
line names the port. If the phux connection drops, the server stops
listening and open connections close; after the reconnect it listens on the
same port again (also across phux upgrade). If another program took one
of those ports meanwhile, that -R is dropped with a warning and the rest of
the run goes on. Each connection to it is one
of the 32 forwards a phux connection holds, as each -L connection is;
past that, new ones are closed at once.
-L, @N and -R combine in one run, which ends at Ctrl-C or once none is
left: each closed by another client, or a -R the server could not take
again.
phux forward ls --remote mini # every forward listener, from every client
phux forward close 3 --remote mini
ls (--json for scripts) shows each listener’s id, -L or -R, where it
listens and what it reaches, the client holding it, since when, and for a
server listener its open connections and bytes each way. It lists
phux forward -L and @N, and the ports Rune forwards for a link, next to
-R. close stops one, whichever client holds it: a server listener stops
accepting and the connections it already took go on until they end; a
listener on a client stops listening there. Either way the client that held
it is told, and does not listen on it again after a reconnect. A listener
ends with its client’s connection. Listing needs inventory@global;
listening and closing need input@global, like any forward. A phux
connection registers at most 16 listeners and a server 256, so one holder of
input@global cannot fill the list for everyone; past that, a new one is
refused.
By default the server dials only its own loopback (localhost, names under
it such as app.localhost, 127.0.0.1, ::1, in any case and with or
without the final dot), never looking them up. [forward] in the server’s
config turns forwarding off or adds exact
host:port targets to allow (no wildcards), which the server resolves and
dials as its own user. That default limits mistakes, not a determined holder: forwarding
needs input@global, which can already run commands there. List a target
only if every holder of that right may reach it.
phux forward -L 8080:/run/user/1000/app.sock --remote mini # a socket there
phux forward -R 8080:/tmp/dev.sock --remote mini # a socket here
A target that is an absolute path is a Unix socket. On the server’s side,
-L reaches only a socket path [forward] allow lists, spelled exactly:
there is none by default, and the path is compared as text, never resolved
or followed by the check. The server then dials it as written, following
links, so list only a socket whose directories no untrusted user can
write: there, anyone could replace it with a link to any socket the
server’s user can open. -R carries the server’s port to a socket on this
machine, which only the -R you typed names: this side never dials a
target the server reports. Unix socket targets need phux on both ends
to advertise FORWARD_UNIX, and a client on a platform without Unix
sockets refuses them. Listening on a Unix socket, on either side, is not
offered.
ssh-agent
# config.toml here
[[remote]]
name = "mini"
endpoint = "quic://mini:8788"
forward-agent = true
# forward-agent-keys = ["SHA256:Xr0..."] # only these, as ssh-add -l prints them
Like ssh -A, but for as long as you are attached: while phux attach mini
or Rune shows mini, ssh and git in its panes can use the keys in this
machine’s agent (SSH_AUTH_SOCK; in Rune, [rune] ssh-agent first), from
whichever machine attached last. When that one detaches, the machine attached
before it answers again. Reconnecting offers again. If mini doesn’t forward
agents or there is no agent here, the attach says so once and goes on. With
forward-agent-keys, other keys are neither listed nor signed with.
Each signature is asked first, naming the pane, the host and the key, and anything but a deliberate yes refuses: in the TUI, Left then Enter, or a click on Sign; in Rune, ⌘Return (Ctrl+Shift+Return on Linux) or the button. A question ignores both for half a second, and typing never answers it. Unanswered, it is refused after 60 s. There is no “always allow”. Listing keys is not asked about.
The server must set [forward] agent = true (restart to apply). It then
starts every new pane with SSH_AUTH_SOCK pointing at an owner-only broker
socket beside its own, replacing any agent the server inherited, whether
or not a client is serving. Panes started earlier keep their old value. The
path survives server restarts. The broker passes on only key listing and
signing; adding, removing, locking, and extensions are refused on both
sides, and the client refuses a key its agent does not hold.
A request no client answers fails at once when nobody serves, or after 60 s, and its pane gets a note saying why, at most every five minutes. Only clients that watch the pane see it.
While a client serves, any process in any pane on that server, run by
anyone who can reach the server’s user account, can ask your agent to
sign. The pane in the question is the server’s guess from the asking
process’s session and parents: any process of that user can look like
another pane’s, and one that left its pane (a tmux server, a daemon)
shows as pane unknown and leaves no note. The question does not say what
is signed, so say yes only when you expect a request. Offering needs
input@global.
Without an attached client, or to sign without asking:
phux forward --agent --remote mini
It serves until Ctrl-C and asks on its terminal; anything but y refuses.
Without a terminal every signature is refused, and --yes signs without
asking, which is exactly ssh -A. It obeys forward-agent-keys.
phux: let pane @3 on mini sign with SHA256:Xr0... (me@laptop)? [y/N]
The audit log records each forwarded connection,
each listener’s start and end, and each signature request, never the data. The wire contract (timeouts,
windows, limits, errors) is
phux-protocol/src/forward.rs;
tags are in kinds.
Opening links
A program on a machine with no screen can ask to open a link on yours:
phux open-url https://phux.sh
With [defaults] browser-shim = true on the server, panes’ programs do it by
themselves: BROWSER is a stand-in that runs phux open-url, also last on
panes’ PATH as xdg-open, so a real one wins. (A login shell that rebuilds
PATH drops it.) When nothing opens the link, the stand-in prints it and
copies it to your clipboard.
The terminal UI or Rune asks, if it is the client that last typed in the pane:
it names the machine, the pane and the whole link. O opens it, once the
question has been up for a second with no key pressed; Enter or Esc declines,
and so does no answer for 60 s. It always asks. Only http and https links
with a host and no user name are asked about, with a non-ASCII host in
punycode. One request per pane waits at a time, eight per server.
Nobody is asked for a pane on a linked machine, from a phone, or from a terminal UI that itself runs over SSH, in a phux pane, or without a desktop.
A localhost link from another machine’s pane means that machine, and so
does a sign-in that comes back to a localhost port in its redirect_uri
(or redirect, callback, return_to, next, continue, and their
_url and camelCase spellings). Rune
forwards the port over its phux connection before opening either one,
whether the link was asked about, ⌘-clicked, or tapped on a phone. That
covers localhost, *.localhost names, 127.0.0.0/8, [::1], and the
0.0.0.0 and [::] that dev servers print, over http and https with no
user name.
The forward listens on 127.0.0.1 and [::1] here at the same port when no
program on this machine serves it, and on another port otherwise; a
sign-in’s return needs the same port, so a sign-in whose port is taken here
says so instead of opening. The link opens with only its port changed (a
wildcard address opens as localhost, another 127.x.y.z as 127.0.0.1).
The next click reuses the forward. Running forwards are listed in the
palette, where each can be stopped, and all of them stop when the window
leaves that machine. On macOS a program started here on the same port
afterwards, listening on every address, does not get its loopback
connections while the forward runs; stop the forward in the palette. The iOS
app opens a forwarded page in its own browser, because iOS suspends an app
that the system browser covers, and the forward with it.
A page often calls a second port on its machine (an API beside the dev server) by its number, and that call hangs here until the port is forwarded too. So while a forward from a pane runs, Rune follows the pane’s listening ports and offers each other port it serves on loopback or every interface, once in a tip with a Forward button, and in the palette while the pane serves it (Forward localhost:8080 from the pane). It never forwards one unasked. Ports from 32768 up are never offered: that is where a bind to port 0 lands on Linux, macOS, and Windows, which is how test runners, debuggers’ helpers, and editor and MCP servers listen for a moment; a page’s API has a fixed number below it. An accepted port is forwarded on exactly its number here, or the page would still miss it; one already in use here says so. When the pane stops listening on a forwarded port, its palette row says nothing listens there now, and the forward keeps running for the dev server to come back. Once the last forward from a pane stops, its ports are no longer followed. A linked machine’s pane has no ports to offer.
The phone apps get the same decision from phux-client-ffi: open_link
on RemoteClient takes the tapped link and its pane and answers with the
local link to open in the app’s browser, “not a localhost link” (open it
as before), or a refusal to show. list_forwards, stop_forward, and
stop_all_forwards manage the running ones, take_forward_failures drains
what they could not carry after each wake, and stop_connection stops them
all. port_offer names the other ports a forwarded link’s pane serves, each
once, with the offer in words; offerable_ports is every such port the pane
serves now, offered before or not, for a list like the palette’s; and
forward_port forwards one on its own number. Which links forward, which port they take, what is offered, and
every message are phux_client_runtime::local_forward’s open and ports,
shared with Rune. A forward
lives in the app’s process, so the app keeps itself running while one is in
use (on Android, a foreground service): a browser that covers it lets the
system freeze it, and the forward with it.
A forward listens on this machine’s loopback, so any program here can
connect to it and reach that port on the server’s machine as you, as with
ssh -L. On a phone that includes every other app, past the sandbox that
keeps apps apart. Stop forwards you no longer need.
A forward needs a server with [forward] tcp, and each connection needs
input@global there. Nothing is dialed until the page connects (a sign-in’s
callback server answers once), so a refusal, or nothing listening there, is
said in a notice when the first connection fails, once until one gets
through. A pane on a linked machine can’t be forwarded, so its localhost
links don’t open. The terminal UI shows the phux forward -L command to run
first instead.
Asking needs input on the pane. The audit log
records the request and its answer, with the link’s host only. The wire
contract is phux-protocol/src/open_url.rs.