Allow multi-line authorized_keys

Closes #316
This commit is contained in:
Floris Bos 2021-12-20 21:46:37 +01:00
parent 3733b0e4b3
commit 47d331b664

View file

@ -603,16 +603,23 @@ Popup {
addCloudInit("ssh_pwauth: true") addCloudInit("ssh_pwauth: true")
} }
if (radioPubKeyAuthentication.checked) { if (radioPubKeyAuthentication.checked) {
var pubkey = fieldPublicKey.text.replace(/\n/g, "") var pubkey = fieldPublicKey.text
var pubkeyArr = pubkey.split("\n")
if (pubkey.length) { if (pubkey.length) {
addFirstRun("install -o \"$FIRSTUSER\" -m 700 -d \"$FIRSTUSERHOME/.ssh\"") addFirstRun("install -o \"$FIRSTUSER\" -m 700 -d \"$FIRSTUSERHOME/.ssh\"")
addFirstRun("install -o \"$FIRSTUSER\" -m 600 <(echo \""+pubkey+"\") \"$FIRSTUSERHOME/.ssh/authorized_keys\"") addFirstRun("install -o \"$FIRSTUSER\" -m 600 <(printf \""+pubkey.replace(/\n/g, "\\n")+"\") \"$FIRSTUSERHOME/.ssh/authorized_keys\"")
} }
addFirstRun("echo 'PasswordAuthentication no' >>/etc/ssh/sshd_config") addFirstRun("echo 'PasswordAuthentication no' >>/etc/ssh/sshd_config")
addCloudInit(" lock_passwd: true") addCloudInit(" lock_passwd: true")
addCloudInit(" ssh_authorized_keys:") addCloudInit(" ssh_authorized_keys:")
addCloudInit(" - "+pubkey) for (var i=0; i<pubkeyArr.length; i++) {
var pk = pubkeyArr[i].trim();
if (pk) {
addCloudInit(" - "+pk)
}
}
addCloudInit(" sudo: ALL=(ALL) NOPASSWD:ALL") addCloudInit(" sudo: ALL=(ALL) NOPASSWD:ALL")
} }