cmd-run: Automatically inject SSH pubkeys with -p
This just makes `-p` way more convenient rather than having to write up
a custom Ignition config just for this.
@@ -193,6 +193,22 @@ EOF
rowcol=$(stty -a | tr ';' '\n' | grep -e 'rows\|columns' | tr '\n' ' ' )
rowcol=$(echo "stty ${rowcol}" | base64 --wrap 0)
+# if SSH port mapping is requested, automagically inject all the pubkeys
+ssh_pubkeys=""
+if [ -n "${SSH_PORT}" ]; then
+ for pubkey in ~/.ssh/*.pub; do
+ # in case there are no keys
+ if [ ! -f "${pubkey}" ]; then
+ break
+ fi
+ if [ -z "${ssh_pubkeys}" ]; then
+ ssh_pubkeys="\"$(cat "${pubkey}")\""
+ else
+ ssh_pubkeys="${ssh_pubkeys}, \"$(cat "${pubkey}")\""
+ fi
+ done
+fi
+
f=$(mktemp)
cat > "${f}" <<EOF
{
@@ -221,6 +237,16 @@ cat > "${f}" <<EOF
}
]
},
+ "passwd": {
+ "users": [
+ {
+ "name": "core",
+ "sshAuthorizedKeys": [
+ ${ssh_pubkeys}
+ ]
+ }
+ ]
+ },
"systemd": {
"units": [
{
