feat: add sshtmp

Amolith created

Change summary

dot_config/private_fish/functions/sshtmp.fish | 23 ++++++++++++++++++++
1 file changed, 23 insertions(+)

Detailed changes

dot_config/private_fish/functions/sshtmp.fish 🔗

@@ -0,0 +1,23 @@
+function sshtmp --description "Connect to an SSH host using a temporary, one-time key"
+    if test (count $argv) -eq 0
+        echo "Usage: sshtmp [user@]hostname"
+        echo "Example: sshtmp sshtron.zachlatta.com"
+        return 1
+    end
+
+    set -l destination $argv[1]
+
+    set -l tmp_dir (mktemp -d)
+    set -l key_path "$tmp_dir/id_ed25519"
+
+    try
+        ssh-keygen -t ed25519 -f "$key_path" -N "" -C "sshtmp temporary key for $destination" >/dev/null
+        command ssh -i "$key_path" \
+            -o IdentitiesOnly=yes \
+            -o StrictHostKeyChecking=no \
+            -o UserKnownHostsFile=/dev/null \
+            $destination
+    finally
+        rm -rf "$tmp_dir"
+    end
+end