Skip to content

Commit 6a27bf1

Browse files
switch from dropbear to tinysshd
1 parent cff3ae5 commit 6a27bf1

File tree

4 files changed

+78
-3
lines changed

4 files changed

+78
-3
lines changed

initrd-build.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ do_secret_clean() {
2626
}
2727

2828
# ensure dropbear server host keys
29-
do_ssh_host_keys() {
29+
do_dropbear_keys() {
3030

3131
quiet "provide host server ssh keys"
3232

@@ -52,6 +52,22 @@ do_ssh_host_keys() {
5252

5353
}
5454

55+
# ensure tinyssh server host keys
56+
do_tinysshd_keys() {
57+
58+
quiet "provide host server ssh keys"
59+
60+
local keydir=/etc/tinyssh/sshkeydir
61+
62+
mkdir -p $keydir
63+
chmod go-rwx $keydir
64+
65+
plain "convert openssh to tinysshd host key ed25519"
66+
67+
run_command tinyssh-convert -f /etc/ssh/ssh_host_ed25519_key -d $keydir
68+
69+
}
70+
5571
# location of server host keys used by openssh
5672
keypath_openssh() {
5773
local type=$1

initrd-dropbear.service

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
# Provide ssh server in initramfs
44

5+
# TODO
6+
# see #21
7+
# see #22
8+
59
[Unit]
610
Description=Initrd Dropbear Service
711
Documentation=https://github.com/random-archer/mkinitcpio-systemd-tool/blob/master/README.md
@@ -31,11 +35,13 @@ WantedBy=sysinit.target
3135

3236
[X-SystemdTool]
3337

38+
# TODO support new key formats
39+
3440
# enable service
35-
InitrdService=enable
41+
InitrdService=disable
3642

3743
# ensure dropbear server host keys
38-
InitrdBuild=/etc/systemd/system/initrd-build.sh command=do_ssh_host_keys
44+
#InitrdBuild=/etc/systemd/system/initrd-build.sh command=do_dropbear_keys
3945

4046
# include generated dropbear configuration
4147
InitrdPath=/etc/dropbear

initrd-network.service

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ InitrdCall=add_checked_modules /drivers/net/
4343
# runtime location of resolv.conf provided by systemd-resolved.service
4444
InitrdLink=/etc/resolv.conf /run/systemd/resolve/resolv.conf
4545

46+
# ensure consistent host name
47+
InitrdPath=/etc/hostname replace=yes
48+
4649
# include default config file for systemd-resolved.service
4750
InitrdPath=/usr/lib/systemd/resolv.conf
4851

initrd-tinysshd.service

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# This file is part of https://github.com/random-archer/mkinitcpio-systemd-tool
2+
3+
# Provide ssh server in initramfs
4+
5+
# note:
6+
# - tinysshd supports only ed25519 keys
7+
# - make sure opensshd host keys include ed25519 keys
8+
# - make sure remote user account also has ed25519 key pair
9+
10+
# service dependencies:
11+
# - https://www.archlinux.org/packages/community/x86_64/busybox/
12+
# - https://www.archlinux.org/packages/community/x86_64/tinyssh/
13+
# - https://aur.archlinux.org/packages/tinyssh-convert/
14+
15+
[Unit]
16+
Description=Initrd TinySSHD Service
17+
Documentation=https://github.com/random-archer/mkinitcpio-systemd-tool/blob/master/README.md
18+
ConditionPathExists=/etc/initrd-release
19+
DefaultDependencies=no
20+
After=initrd-shell.service
21+
After=initrd-network.service
22+
Before=cryptsetup-pre.target
23+
Requires=initrd-shell.service
24+
Requires=initrd-network.service
25+
26+
[Service]
27+
ExecStart=/usr/bin/busybox tcpsvd -v 0 22 /usr/bin/tinysshd -v /etc/tinyssh/sshkeydir
28+
Restart=always
29+
RestartSec=3s
30+
31+
[Install]
32+
WantedBy=sysinit.target
33+
34+
[X-SystemdTool]
35+
36+
# enable service
37+
InitrdService=enable
38+
39+
# ensure tinyssh keys are based on openssh keys
40+
InitrdBuild=/etc/systemd/system/initrd-build.sh command=do_tinysshd_keys
41+
42+
# provision tinyssh server
43+
InitrdBinary=/usr/bin/tinysshd
44+
45+
# use full busybox (provides tcpsvd applet)
46+
InitrdBinary=/usr/bin/busybox replace=yes
47+
48+
# include tinyssh configuration
49+
InitrdPath=/etc/tinyssh/sshkeydir/.ed25519.sk
50+
InitrdPath=/etc/tinyssh/sshkeydir/ed25519.pk

0 commit comments

Comments
 (0)