Skip to content

Commit 33742de

Browse files
committed
Allow authorized_keys
1 parent ebc52d1 commit 33742de

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ From there, actual system install can be performed as usual with `setup-alpine`
2222
Extra files may be added next to `headless.apkovl.tar.gz` to customise boostrapping configuration (check sample files):
2323
- `wpa_supplicant.conf`[^3] (*mandatory for wifi usecase*): define wifi SSID & password.
2424
- `interfaces`[^3] (*optional*): define network interfaces at will, if defaults DCHP-based are not suitable.
25-
- `ssh_host_*_key*` (*optional*): provide custom ssh keys to be injected (may be stored), instead of using bundled ones[^2] (not stored). Providing an empty key file will trigger new keys generation (ssh server may take longer to start).
25+
- `authorized_keys` (*optional*): provide client's public SSH key to secure `root` ssh login.
26+
- `ssh_host_*_key*` (*optional*): provide server's custom ssh keys to be injected (may be stored), instead of using bundled ones[^2] (not stored). Providing an empty key file will trigger new keys generation (ssh server may take longer to start).
2627
- `unattended.sh`[^3] (*optional*): create custom automated deployment script to further tune & extend actual setup (backgrounded).
2728

2829

headless.apkovl.tar.gz

109 Bytes
Binary file not shown.

overlay/etc/local.d/headless.start

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ exec 1>/dev/console 2>&1
4747

4848
logger -st ${0##*/} "Alpine Linux headless bootstrap v$VERSION by macmpi"
4949

50-
mkdir /tmp/.trash
50+
install -dm 0700 /tmp/.trash
5151

5252
# grab used ovl filename from dmesg
5353
ovl="$( dmesg | grep -o 'Loading user settings from .*:' | awk '{print $5}' | sed 's/:.*$//' )"
@@ -132,12 +132,26 @@ _apk add openssh
132132
_preserve "/etc/ssh/sshd_config"
133133
_preserve "/etc/conf.d/sshd"
134134

135-
cat <<-EOF >> /etc/ssh/sshd_config
136-
AuthenticationMethods none
137-
PermitEmptyPasswords yes
135+
cat <<-EOF > /etc/ssh/sshd_config
138136
PermitRootLogin yes
139137
Banner /tmp/.trash/banner
140138
EOF
139+
140+
if install -m600 "${ovlpath}/authorized_keys" /tmp/.trash/authorized_keys; then
141+
logger -st ${0##*/} "Enabling public key SSH authentication..."
142+
cat <<-EOF >> /etc/ssh/sshd_config
143+
AuthenticationMethods publickey
144+
AuthorizedKeysFile /tmp/.trash/authorized_keys
145+
# relax strict mode as authorized_keys are inside /tmp
146+
StrictModes no
147+
EOF
148+
else
149+
logger -st ${0##*/} "No SSH authentication."
150+
cat <<-EOF >> /etc/ssh/sshd_config
151+
AuthenticationMethods none
152+
PermitEmptyPasswords yes
153+
EOF
154+
fi
141155

142156
# Banner file
143157
warn=""

0 commit comments

Comments
 (0)