Skip to content

Commit

Permalink
armbian-firstrun: Optionally skip OpenSSH host key regeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
davidandreoletti authored and igorpecovnik committed Sep 15, 2024
1 parent baf99a7 commit f145fc2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
3 changes: 3 additions & 0 deletions lib/functions/bsp/armbian-bsp-cli-deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@ function board_side_bsp_cli_postinst_finish() {
if [ ! -f "/etc/default/armbian-zram-config" ] && [ -f /etc/default/armbian-zram-config.dpkg-dist ]; then
mv /etc/default/armbian-zram-config.dpkg-dist /etc/default/armbian-zram-config
fi
if [ ! -f "/etc/default/armbian-firstrun" ]; then
mv /etc/default/armbian-firstrun.dpkg-dist /etc/default/armbian-firstrun
fi

if [ -L "/usr/lib/chromium-browser/master_preferences.dpkg-dist" ]; then
mv /usr/lib/chromium-browser/master_preferences.dpkg-dist /usr/lib/chromium-browser/master_preferences
Expand Down
9 changes: 8 additions & 1 deletion lib/functions/rootfs/distro-agnostic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,14 @@ function install_distribution_agnostic() {

# enable additional services, if they exist.
display_alert "Enabling Armbian services" "systemd" "info"
[[ -f "${SDCARD}"/lib/systemd/system/armbian-firstrun.service ]] && chroot_sdcard systemctl --no-reload enable armbian-firstrun.service
if [[ -f "${SDCARD}"/lib/systemd/system/armbian-firstrun.service ]]; then
# Note: armbian-firstrun starts before the user has a chance to edit the env file's values.
# Exceptionaly, the env file can be edited during image build time
if test -n "$OPENSSHD_REGENERATE_HOST_KEYS"; then
sed -i "s/\(^OPENSSHD_REGENERATE_HOST_KEYS *= *\).*/\1$OPENSSHD_REGENERATE_HOST_KEYS/" "${SDCARD}"/etc/default/armbian-firstrun
fi
chroot_sdcard systemctl --no-reload enable armbian-firstrun.service
fi
[[ -f "${SDCARD}"/lib/systemd/system/armbian-zram-config.service ]] && chroot_sdcard systemctl --no-reload enable armbian-zram-config.service
[[ -f "${SDCARD}"/lib/systemd/system/armbian-hardware-optimize.service ]] && chroot_sdcard systemctl --no-reload enable armbian-hardware-optimize.service
[[ -f "${SDCARD}"/lib/systemd/system/armbian-ramlog.service ]] && chroot_sdcard systemctl --no-reload enable armbian-ramlog.service
Expand Down
6 changes: 6 additions & 0 deletions packages/bsp/common/etc/default/armbian-firstrun.dpkg-dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# configuration values for the armbian-firstrun service

# Delete + regenerate OpenSSH host keys
# true = delete + generate host keys
# false = no deletion / no generation for host keys
OPENSSHD_REGENERATE_HOST_KEYS=true
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ After=ssh.service
[Service]
Type=simple
RemainAfterExit=yes
EnvironmentFile=/etc/default/armbian-firstrun
ExecStart=/usr/lib/armbian/armbian-firstrun start
TimeoutStartSec=2min

Expand Down
16 changes: 10 additions & 6 deletions packages/bsp/common/usr/lib/armbian/armbian-firstrun
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ case "$1" in
[[ -f /etc/systemd/system/armbian-live-patch.service ]] && systemctl --no-reload enable armbian-live-patch.service

# SSH Keys creation
rm -f /etc/ssh/ssh_host*
read entropy_before </proc/sys/kernel/random/entropy_avail
dpkg-reconfigure openssh-server >/dev/null 2>&1
service ssh restart
read entropy_after </proc/sys/kernel/random/entropy_avail
echo -e "\n### [firstrun] Recreated SSH keys (entropy: ${entropy_before} ${entropy_after})" >>${Log}
if [[ "${OPENSSHD_REGENERATE_HOST_KEYS}" = true ]]; then
rm -f /etc/ssh/ssh_host*
read entropy_before </proc/sys/kernel/random/entropy_avail
dpkg-reconfigure openssh-server >/dev/null 2>&1
service ssh restart
read entropy_after </proc/sys/kernel/random/entropy_avail
echo -e "\n### [firstrun] Recreated SSH keys (entropy: ${entropy_before} ${entropy_after})" >>${Log}
else
echo -e "\n### [firstrun] SSH host keys unchanged" >>${Log}
fi

# get rid of purple background color in newt apps whiptail, partimage, debconf ... Reverting to Debian look.
[[ -f /etc/newt/palette ]] && sed -e 's/magenta/blue/g' -i /etc/newt/palette
Expand Down

0 comments on commit f145fc2

Please sign in to comment.