summaryrefslogtreecommitdiff
path: root/stage2
diff options
context:
space:
mode:
authorDaniel F. Dickinson <cshored@danielfdickinson.ca>2020-09-08 16:16:07 -0400
committerGitHub <noreply@github.com>2020-09-08 21:16:07 +0100
commitc1a7dae113ce943abe8bf5d5ab36fb7aac829fd2 (patch)
tree117a02dea1db96a327456dd1cc7b3f974c345b57 /stage2
parentd6207a620a10ba0ec25f95a637d3fdd272b47e84 (diff)
Enable adding SSH pubkey and setting pubkey only (#380)
This commit add the ability to specify an SSH public key as well as the option to disable password authentication and only allow public key authentication for SSH. Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
Diffstat (limited to 'stage2')
-rwxr-xr-xstage2/01-sys-tweaks/01-run.sh12
1 files changed, 12 insertions, 0 deletions
diff --git a/stage2/01-sys-tweaks/01-run.sh b/stage2/01-sys-tweaks/01-run.sh
index 8d28adc..c1836f9 100755
--- a/stage2/01-sys-tweaks/01-run.sh
+++ b/stage2/01-sys-tweaks/01-run.sh
@@ -11,6 +11,18 @@ install -m 644 files/console-setup "${ROOTFS_DIR}/etc/default/"
install -m 755 files/rc.local "${ROOTFS_DIR}/etc/"
+if [ -n "${PUBKEY_SSH_FIRST_USER}" ]; then
+ install -v -m 0700 -o 1000 -g 1000 -d "${ROOTFS_DIR}"/home/"${FIRST_USER_NAME}"/.ssh
+ echo "${PUBKEY_SSH_FIRST_USER}" >"${ROOTFS_DIR}"/home/"${FIRST_USER_NAME}"/.ssh/authorized_keys
+ chown 1000:1000 "${ROOTFS_DIR}"/home/"${FIRST_USER_NAME}"/.ssh/authorized_keys
+ chmod 0600 "${ROOTFS_DIR}"/home/"${FIRST_USER_NAME}"/.ssh/authorized_keys
+fi
+
+if [ "${PUBKEY_ONLY_SSH}" = "1" ]; then
+ sed -i -Ee 's/^#?[[:blank:]]*PubkeyAuthentication[[:blank:]]*no[[:blank:]]*$/PubkeyAuthentication yes/
+s/^#?[[:blank:]]*PasswordAuthentication[[:blank:]]*yes[[:blank:]]*$/PasswordAuthentication no/' "${ROOTFS_DIR}"/etc/ssh/sshd_config
+fi
+
on_chroot << EOF
systemctl disable hwclock.sh
systemctl disable nfs-common