I'm looking to automatically setup up my SSH keys on a fresh Ubuntu Server 20.04 install on a Raspberry Pi 4 - mostly as a learning exercise. I'm trying to use the ssh_import_id
option of cloud-init to pull my SSH public key from my GitHub account and add it to ~/.ssh/authorized_keys
for the pi
user.
I cannot seem to get the ssh_import_id
config to kick in. The ~/.ssh
directory is never made for the pi
user, and there are no logs relating to anything to do with pulling a key from GitHub/ssh_import_id in /var/logs/cloud-init.log
or /var/log/cloud-init-output.log
.
The current contents of my user-data
on the root of the SD card:
- name: pi
groups: [sudo]
sudo: ALL=(ALL) NOPASSWD:ALL
ssh_import_id: # import public key from github
- gh:my_cool_github_account
lock_passwd: true # disable password login
Everything works fine if I input the public key manually using ssh_authorized_keys
, which will suit my workflow but I'm hoping to get the GitHub thing setup as it's snazzy.
My understanding of cloud-init
is definitely a little basic, so I may have missed something. I'm triggering changes by running cloud-init clean
and then cloud-init init
, which feels like it's running fine as it's remaking users/general bits/the root ssh keys and fingerprint.
I'm presumably also using the NoCloud
datasource.
Can anyone help me figure out what I'm doing wrong?