0

I have an init script that mkdir -p raspi-os-image/home/pi/.ssh and adds a SSH key to authorized_keys inside. The problem is, when doing this it needs to be done as root and then once the system is initialized, the pi user cannot save anything new into known_hosts due to ~/.ssh being owned by root.

When I am on the linux environment that has the OS image mounted (where I make the mkdir call) I am unable to run chown pi:pi raspi-os-image/home/pi/.ssh because pi is not a valid user on this system.

Is there any way to do this? Must I create a pi user on this system?

  • Have you considered moving the configuration to the Pi with something like Puppet, chef or Ansible? – Steve Robillard Apr 25 '17 at 3:35
1

The directory does not need to be owned by user pi.

Indeed the filesystem has no inherent knowledge of users.

pi is user 1000, and your system probably has a user 1000.

You should be able to use numeric users with chown.

  • Yeah, when I added a user pi to that system and used that, it set to user 1001 (pretty straightforward to see why that is), and that doesnt match pi on the pi, and it works even worse than if it was root... so thanks for showing me that this is can be the ID too. – Steven Lu Apr 25 '17 at 4:16
0

Why not just SCP the files to the RPI, and then sudo chown pi:pi file when logged on to the RPI?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.