Try to replace dropbear by openssh-server using imagebuilder #9

Merged
PeterSurda merged 2 commits from lee.miller/openwrt:openssh into main 2023-02-09 10:02:20 +01:00
Collaborator

Hi!

This is a possible simple solution for #5

Hi! This is a possible simple solution for #5
lee.miller force-pushed openssh from 1f284ec032 to 15b8d70716 2023-01-27 23:24:49 +01:00 Compare
Owner

Ok but a couple of issues.

  • It doesn't start by default. To start by default, it looks like you need to make these symlinks:
/etc/rc.d/S50sshd -> ../init.d/sshd
/etc/rc.d/K50sshd -> ../init.d.sshd
  • Doesn't accept root password. Which I don't want anyway, but I'd also like to disable password authentication explicitly in /etc/ssh/sshd_config

  • I want to populate default authorized_keys

ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBI8QxHD/hCeA/8VY0qkQEh5LNedXMDR7o+qJ0KlsstqebtN/Egwto37arI0x/GRDD0QRSzpgm2AVsTeDGOV1AAw= ssh_token@mireille
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7Pebz7cNpL/Hikzfwzdnujcd1BWw4D4e1OXQaoCGcq2/gL+Wym8InL5qZ5hOgaF8lRVX5ys7m75uOyg8LOIRu0A27TzWzf9brV8TF5rsIhHYSK0CAA81G5NqOQgP3b7SANcs3PEWtxz+OeqFo7dcsQZijczRNunM73CBsTFZQCmNE2ZBh2QaQ1d/1lmYTqGlJ8DJrqeXXVc3S1Jln2nZ49XQMqdG49KvU66Xhd8kaukucDBl8iNLWpQ+N9Ao1SOnNlJVpLi6XUy9Hx3X3wVbrLQaHslIG6+AeZGpO/l3gKrQM3fjM2H+w9ow1rWcMdHgjxWZUryE7K1vzbpm4vNIf shurdeek@brusli
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDVrfim4EMF7FzAnQF51frpsPgNJxfkzvBEC80wgwwP0AzD2iFPS57a6sXbie+sX7ALX89gmRwFtrKOwGYRYoQfU6dAhPirbpKY4BcTQx8N31fazceVJL0Y1kqSngNj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kAKlTItbfnu0y/8RB+zRYt111ZmlfvbczsX5qNwaJoEwAxrkjtA5D/BnvSMSrxvmkRKtUMnXLOldr3hrZjRuTAmP3YxwcGfrNWv/+UcNSf1QE6NRJDxOSrBQ7qYAMaiq+6acztY7nvVWJ9ZntFOOaWOhkVWoCeDWmBEjRlQ1hCIMxm8BhopFaumkEVnnku/OskS2ZD6SFe6aKSXmaHV4nwtiQ5GiwdIEnrQ1GzK3h7SfRu/BXRhcnnPGIeRBuKaq/P1bqLsnFChPsrvkEP1Z/daosaGanIzODxkFO0rAkdScI4kHUhZba0vb3ahV4JpAwaH8dEQm0nkuxbUe2YR3eii6bMh9zv7BiXJnyTQtRzdYn4Im2eeSTOIlckohJWunhdnU9cRy8lFH7zILmr6sqxmjXxFzXS1KUas/+0yD4lgDDlsQtF6qI6pA75/tmK8pIq8915ShZA14bwDXWYLBDx+sy24iyG+kpSumzDqyNXvm+Z+bHHYAjI1uUcTKltnPQ4nJrhmY2+M4IhmL1LVyQU7K63BYlTtuV1106Xa8tQnzTblJKXPMqy/3LlV4TbSyUNJR0a5ma7LR/vxeloL1gxRQCQYJxcM1MD6VroqKUPIzhOWCdEPcM2+9oySOZbqDKfrenTMQ== yubikey@lenovopadpro
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBCJfhSCRSrz1rSFtSWNt6EzL08l1DOjcEKBREUwtKZgxDJcj2MdXH6Z7otnJUUmOqf43x35eayCpQz8EG8eKJio= johndoe@macbook.pro@secretive.MacBook-Pro.local
Ok but a couple of issues. - [x] It doesn't start by default. To start by default, it looks like you need to make these symlinks: ``` /etc/rc.d/S50sshd -> ../init.d/sshd /etc/rc.d/K50sshd -> ../init.d.sshd ``` - [x] Doesn't accept root password. Which I don't want anyway, but I'd also like to disable password authentication explicitly in `/etc/ssh/sshd_config` - [x] I want to populate default `authorized_keys` ``` ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlz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H7zILmr6sqxmjXxFzXS1KUas/+0yD4lgDDlsQtF6qI6pA75/tmK8pIq8915ShZA14bwDXWYLBDx+sy24iyG+kpSumzDqyNXvm+Z+bHHYAjI1uUcTKltnPQ4nJrhmY2+M4IhmL1LVyQU7K63BYlTtuV1106Xa8tQnzTblJKXPMqy/3LlV4TbSyUNJR0a5ma7LR/vxeloL1gxRQCQYJxcM1MD6VroqKUPIzhOWCdEPcM2+9oySOZbqDKfrenTMQ== yubikey@lenovopadpro ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBCJfhSCRSrz1rSFtSWNt6EzL08l1DOjcEKBREUwtKZgxDJcj2MdXH6Z7otnJUUmOqf43x35eayCpQz8EG8eKJio= johndoe@macbook.pro@secretive.MacBook-Pro.local ```
lee.miller force-pushed openssh from 756a744c4f to c1e61f67ee 2023-02-02 04:42:56 +01:00 Compare
Owner

The PR looks promising, let me test it.

The PR looks promising, let me test it.
Owner

Something weird is happening when trying to boot this. dmesg shows that the /tmp/overlay can't be mounted, and without the overlay the system doesn't work properly. I can login via console but nothing works properly. It's as if the image was corrupt or something. I flashed the microSD card both on a mac and linux and I get the same result.

Something weird is happening when trying to boot this. `dmesg` shows that the /tmp/overlay can't be mounted, and without the overlay the system doesn't work properly. I can login via console but nothing works properly. It's as if the image was corrupt or something. I flashed the microSD card both on a mac and linux and I get the same result.
Owner

After further testing, it looks to be some filesystem weirdness. I modify distroconfig.txt to enable the USB, as otherwise I can't use the keyboard. If I do this before first boot, the root filesystem gets screwed up or something. So I have to boot first, then power down, edit distroconfig.txt (on another machine) and then put the SD card back into the device and boot again.

Now regarding openssh:

  • /etc/uci-defaults/99-custom is executed upon each boot. Maybe then as a last step, it should remove itself?
  • openssh runs correctly
  • PermitRootLogin no should be replaced with PasswordAuthentication no
  • the authorized_keys don't get deployed and there is no /root/.ssh directory. I'm not sure ~ will work inside the uci-defaults script but maybe I'm wrong
After further testing, it looks to be some filesystem weirdness. I modify distroconfig.txt to enable the USB, as otherwise I can't use the keyboard. If I do this before first boot, the root filesystem gets screwed up or something. So I have to boot first, then power down, edit distroconfig.txt (on another machine) and then put the SD card back into the device and boot again. Now regarding openssh: - [ ] `/etc/uci-defaults/99-custom` is executed upon each boot. Maybe then as a last step, it should remove itself? - [x] openssh runs correctly - [ ] `PermitRootLogin no` should be replaced with `PasswordAuthentication no` - [ ] the `authorized_keys` don't get deployed and there is no /root/.ssh directory. I'm not sure `~` will work inside the uci-defaults script but maybe I'm wrong
lee.miller force-pushed openssh from c1e61f67ee to 33cf5864e1 2023-02-02 17:59:20 +01:00 Compare
Author
Collaborator
  • PermitRootLogin no should be replaced with PasswordAuthentication no

It seems to be set by default, at least staging_dir/target-aarch64_cortex-a72_musl/root-bcm27xx/etc/ssh/sshd_config has it uncommented. There is also PermitRootLogin prohibit-password mentioned as default.

> - [ ] `PermitRootLogin no` should be replaced with `PasswordAuthentication no` It seems to be set by default, at least `staging_dir/target-aarch64_cortex-a72_musl/root-bcm27xx/etc/ssh/sshd_config` has it uncommented. There is also `PermitRootLogin prohibit-password` mentioned as default.
Author
Collaborator
  • /etc/uci-defaults/99-custom is executed upon each boot. Maybe then as a last step, it should remove itself?

The doc says: If they exit with code 0 they are deleted afterwards.

> - [ ] `/etc/uci-defaults/99-custom` is executed upon each boot. Maybe then as a last step, it should remove itself? The doc [says](https://openwrt.org/docs/guide-developer/uci-defaults#uci_defaults): If they exit with code 0 they are deleted afterwards.
Owner
  • PermitRootLogin no should be replaced with PasswordAuthentication no

It seems to be set by default, at least staging_dir/target-aarch64_cortex-a72_musl/root-bcm27xx/etc/ssh/sshd_config has it uncommented. There is also PermitRootLogin prohibit-password mentioned as default.

When I boot it, sshd_config has PasswordAuthentication commented. If I try to ssh in like that, it's asking for password. If I manually add PasswordAuthentication no, then it doesn't ask for password (i.e. and only checks keys).

> > > - [ ] `PermitRootLogin no` should be replaced with `PasswordAuthentication no` > > It seems to be set by default, at least `staging_dir/target-aarch64_cortex-a72_musl/root-bcm27xx/etc/ssh/sshd_config` has it uncommented. There is also `PermitRootLogin prohibit-password` mentioned as default. When I boot it, `sshd_config` has `PasswordAuthentication` commented. If I try to ssh in like that, it's asking for password. If I manually add `PasswordAuthentication no`, then it doesn't ask for password (i.e. and only checks keys).
Owner
  • /etc/uci-defaults/99-custom is executed upon each boot. Maybe then as a last step, it should remove itself?

The doc says: If they exit with code 0 they are deleted afterwards.

It looks like the other default files are deleted upon first boot, just the 99-custom stays there. Why? Don't know. Maybe /sbin isn't in PATH so service doesn't resolve?

> > > - [ ] `/etc/uci-defaults/99-custom` is executed upon each boot. Maybe then as a last step, it should remove itself? > > The doc [says](https://openwrt.org/docs/guide-developer/uci-defaults#uci_defaults): If they exit with code 0 they are deleted afterwards. It looks like the other default files are deleted upon first boot, just the 99-custom stays there. Why? Don't know. Maybe `/sbin` isn't in PATH so `service` doesn't resolve?
PeterSurda requested changes 2023-02-03 03:23:28 +01:00
@ -50,0 +53,4 @@
mkdir -p files/etc/uci-defaults
cat << "EOF" > files/etc/uci-defaults/99-custom
echo "PasswordAuthentication no" >> /etc/ssh/sshd_config
mkdir -p ~/.ssh
Owner

this works now, but ~ is /

this works now, but `~` is `/`
@ -50,0 +54,4 @@
cat << "EOF" > files/etc/uci-defaults/99-custom
echo "PasswordAuthentication no" >> /etc/ssh/sshd_config
mkdir -p ~/.ssh
mv authorized_keys ~/.ssh/
Owner

I think this is not run. Maybe it's about the current directory?

I think this is not run. Maybe it's about the current directory?
lee.miller force-pushed openssh from 04a7a3bb64 to 9e2394be2b 2023-02-03 13:40:30 +01:00 Compare
Owner

Looks ok, I'll be able to test on Tuesday.

Looks ok, I'll be able to test on Tuesday.
Owner

key is now in the right location. The permissions are too loose though. Can we maybe put it into the subdirectories into files? Like files/root/.ssh/authorized_keys? Then you can skip the mkdir and mv

regarding sshd, debugging revealed that

  • it's already enabled by default, so no need to enable, but do need to restart instead of start
  • you need to use /sbin/service and not just service
key is now in the right location. The permissions are too loose though. Can we maybe put it into the subdirectories into `files`? Like `files/root/.ssh/authorized_keys`? Then you can skip the `mkdir` and `mv` regarding sshd, debugging revealed that - it's already enabled by default, so no need to `enable`, but do need to `restart` instead of `start` - you need to use `/sbin/service` and not just `service`
lee.miller force-pushed openssh from 9e2394be2b to 2f3be6009c 2023-02-08 15:26:07 +01:00 Compare
Owner

Ok it works except he permissions for /root/.ssh and /root/.ssh/authorized keys should be more restrictive. I'll merge, you can fix it in a separate PR.

Ok it works except he permissions for /root/.ssh and /root/.ssh/authorized keys should be more restrictive. I'll merge, you can fix it in a separate PR.
PeterSurda approved these changes 2023-02-09 10:02:13 +01:00
PeterSurda merged commit 2f3be6009c into main 2023-02-09 10:02:20 +01:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Sysdeploy/openwrt#9
No description provided.