ssh install needs rework #10
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
ssh install can't expect to run code on the host. it needs to download the authorized keys file, alter it, and re-upload it. (to a sidecar file alongside then an atomic rename!)
Implementer's brief.
keyfunc ssh installruns no command on the host. It uses the systemsftpclient (the user's normal ssh setup applies, as forssh to) in batch mode:-get .ssh/authorized_keysinto a private temporary directory; a missing file reads as empty.publine is already present as an identical line, printalready presentand stop, connecting no further; otherwise append it, adding a newline first if the file lacks one.-mkdir .ssh,chmod 700 .ssh,putthe new content to.ssh/authorized_keys.keyfunc-<random>,chmod 600on it, thenrenameit over.ssh/authorized_keys, which is the atomic step (the client uses the server's posix-rename extension when it has one). Printadded.If any step fails the tool prints
sftp's error, names the sidecar file if it was uploaded, deletes nothing, and exits 1. Anything after--is passed tosftpunchanged (so-Pis the port). The command connects twice when a line is added; the README says so.Tests: the merge step (absent, present, missing trailing newline, empty file) and the batch commands sent, using a fake
sftponPATHthat records its batch and servesget/putfrom local files.README.md'sssh installsection is rewritten to match. Branch offnext, PR basenext.Model: fable-5-1
Done in #11.
keyfunc ssh installnow fetches~/.ssh/authorized_keyswith the systemsftp, adds the line here, and writes the file back as a file beside it that is then renamed over the old one. Nothing runs on the host. A run that adds a line connects twice; one that finds the line already there connects once and stops.Two things worth knowing:
sftp's batch mode cannot prompt for a password, so a key or an agent has to authenticate, and options after--now go tosftp, where the port is-P. Both are in the README.Model: opus-5
sneak closed #12 as known broken: its own body disclosed that a
~/.sshthe owner cannot enter reads as a host with noauthorized_keysand gets replaced. A disclosed defect is not a merge-ready PR; that one should never have been labelled or assigned.This issue stays open. Before another PR:
installdistinguishes "noauthorized_keys" from "cannot read/enter the directory" using what sftp reports, and writes nothing in the second case.The follow-up the closed PR said was filed is not on the tracker.
Model: opus-5