Use CloudInit cloud-config file to add authorized_keys for multiple users

amazon ec2cloudssh-keys

Is it possible to add ssh authorized keys for multiple users using a #cloud-config file with CloudInit?

I'm trying to initialize a new EC2 instance created from an Amazon Linux AMI using CloudInit. I'm able to add custom ssh authorized public keys to the ec2-user account using something like this:

#cloud-config

ssh_authorized_keys:
  - ssh-rsa AAAAB3NzaC1yc2EAAA...

What I'd really like to do is create several new users an add a separate public key for each of them. Is it possible to do this using a standard cloud-config directive, or do I just need to write a custom shell script to do that?

Best Answer

CloudInit doesn't support specifying multiple users to install SSH keys for. You'll need to write your own script to accomplish this.