I'm trying to write an SSH key to /root/.ssh/authorized_keys
during an automated 20.04 server install, but it fails, probably because of permission problems.
The 1st command is successful, the 2nd fails:
late-commands:
- echo 'test2' > /target/etc/test2
- echo 'ssh-rsa ...' > /target/root/.ssh/authorized_keys
How could I achieve that?
I just had the same problem. It would certainly be better to solve this with the
users
block from could-init oruser-data
as mentioned here, but I couldn't get either of them to work.So I went with your solution and added a
mkdir /target/root/.ssh
to thelate-commands
. Not pretty but works.