Skip to content

Commit f32e959

Browse files
committed
installer: allow providing SSH public keys as files (refs #52)
1 parent 8e4f361 commit f32e959

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

doc/INSTALL_CUSTOM.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
## SSH
4343

4444
| Parameter | Default | Options | Description |
45-
|--------------------|---------|---------|------------------------------------------------------------------------------------------------------|
46-
| `user_ssh_pubkey` | | | Public SSH key for created user; the public SSH key must be on a single line, enclosed in quotes |
47-
| `root_ssh_pubkey` | | | Sets public SSH key for root login. The public SSH key must be on a single line, enclosed in quotes. |
45+
|--------------------|---------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
46+
| `user_ssh_pubkey` | | | Public SSH key for created user; the public SSH key must be on a single line, enclosed in quotes. Alternatively, a file can be specified which is located in the `config/files` directory. |
47+
| `root_ssh_pubkey` | | | Sets public SSH key for root login. The public SSH key must be on a single line, enclosed in quotes. Alternatively, a file can be specified which is located in the `config/files` directory. |
4848
| `root_ssh_pwlogin` | `1` | `0`/`1` | Set to 0 to disable ssh password login for root. |
4949
| `ssh_pwlogin` | | `0`/`1` | Set to 0 to disable ssh password login completely. |
5050

scripts/opt/raspberrypi-ua-netinst/install.sh

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,16 +1084,23 @@ if [ -n "${rootpw}" ]; then
10841084
fi
10851085
# add SSH key for root (if provided)
10861086
if [ -n "${root_ssh_pubkey}" ]; then
1087-
echo -n " Setting root SSH key... "
1087+
echo -n " Setting root SSH key"
10881088
if mkdir -p /rootfs/root/.ssh && chmod 700 /rootfs/root/.ssh; then
1089-
echo "${root_ssh_pubkey}" > /rootfs/root/.ssh/authorized_keys
1089+
if [ -f "/bootfs/raspberrypi-ua-netinst/config/files/${root_ssh_pubkey}" ]; then
1090+
echo -n " from file '${root_ssh_pubkey}'... "
1091+
cp "/bootfs/raspberrypi-ua-netinst/config/files/${root_ssh_pubkey}" /rootfs/root/.ssh/authorized_keys | fail
1092+
echo "OK"
1093+
else
1094+
echo -n "... "
1095+
echo "${root_ssh_pubkey}" > /rootfs/root/.ssh/authorized_keys
1096+
fi
1097+
echo -n " Setting permissions on root SSH authorized_keys... "
1098+
chmod 600 /rootfs/root/.ssh/authorized_keys || fail
1099+
echo "OK"
10901100
else
1101+
echo -n "... "
10911102
fail
10921103
fi
1093-
echo "OK"
1094-
echo -n " Setting permissions on root SSH authorized_keys... "
1095-
chmod 600 /rootfs/root/.ssh/authorized_keys || fail
1096-
echo "OK"
10971104
fi
10981105
# openssh-server in jessie doesn't allow root to login with a password
10991106
if [ "${root_ssh_pwlogin}" = "1" ]; then
@@ -1124,20 +1131,26 @@ if [ -n "${username}" ]; then
11241131
fi
11251132
# add SSH key for user (if provided)
11261133
if [ -n "${user_ssh_pubkey}" ]; then
1127-
echo -n " Setting SSH key for '${username}'... "
1128-
ssh_dir="/rootfs/home/${username}/.ssh"
1129-
if mkdir -p "${ssh_dir}" && chmod 700 "${ssh_dir}"; then
1130-
echo "${user_ssh_pubkey}" > "${ssh_dir}/authorized_keys"
1134+
echo -n " Setting SSH key for '${username}'"
1135+
if mkdir -p "/rootfs/home/${username}/.ssh" && chmod 700 "/rootfs/home/${username}/.ssh"; then
1136+
if [ -f "/bootfs/raspberrypi-ua-netinst/config/files/${user_ssh_pubkey}" ]; then
1137+
echo -n " from file '${user_ssh_pubkey}'... "
1138+
cp "/bootfs/raspberrypi-ua-netinst/config/files/${user_ssh_pubkey}" "/rootfs/home/${username}/.ssh/authorized_keys" | fail
1139+
echo "OK"
1140+
else
1141+
echo -n "... "
1142+
echo "${user_ssh_pubkey}" > "/rootfs/home/${username}/.ssh/authorized_keys"
1143+
fi
1144+
echo -n " Setting owner as '${username}' on SSH directory... "
1145+
chroot /rootfs /bin/chown -R "${username}:${username}" "/home/${username}/.ssh" || fail
1146+
echo "OK"
1147+
echo -n " Setting permissions on '${username}' SSH authorized_keys... "
1148+
chmod 600 "/rootfs/home/${username}/.ssh/authorized_keys" || fail
1149+
echo "OK"
11311150
else
1151+
echo -n "... "
11321152
fail
11331153
fi
1134-
echo "OK"
1135-
echo -n " Setting owner as '${username}' on SSH directory... "
1136-
chroot /rootfs /bin/chown -R "${username}:${username}" "/home/${username}/.ssh" || fail
1137-
echo "OK"
1138-
echo -n " Setting permissions on ${username} SSH authorized_keys... "
1139-
chmod 600 "${ssh_dir}/authorized_keys" || fail
1140-
echo "OK"
11411154
fi
11421155
if [ -n "${userpw}" ]; then
11431156
echo -n " Setting password for '${username}'... "

0 commit comments

Comments
 (0)