5

Using debian preseeding, I want to copy a public key to /root/.ssh/authorized_keys with correct permissions so that I can use ansible to configure the rest of system.

I already selected openssh-server to be installed by selecting d-i pkgsel/include string openssh-server build-essential in the preseed file.

Would this late command work?

d-i preseed/late_command string in-target mkdir -p /root/.ssh; \
in-target /bin/sh -c "echo 'ssh-ed25519 AAAAC3NzaC1IAg1wilR9asDXIPwTsvZXasdTXqasdKv0rIqqweAtxGVgup foobar' >> /root/.ssh/authorized_keys"; \
in-target chown -R root:root /root/.ssh/; \
in-target chmod 644 /root/.ssh/authorized_keys; \
in-target chmod 700 /root/.ssh/
Cruise5
  • 456
  • 3
  • 17
  • the `preseed.cfg`-template contains a network-section where you can edit the line `#d-i network-console/authorized_keys_url string http://10.0.0.1/openssh-key`. maybe is this a feature you are looking for. – anion Dec 21 '22 at 22:16
  • @anion That is *not* the authorized key file for the root user in the target system. – inta Jun 28 '23 at 14:15

1 Answers1

1

Yes, that's the way. There's nothing more to say, but I need 30 characters.

bstabens
  • 49
  • 5