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:


  - 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?


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

  • That's what I figured, but the documentation on CloudInit is so spotty I figured there was a chance someone else knew of a feature I didn't. Thanks for the confirmation.
    – Mike Deck
    Feb 4 '13 at 19:01
  • @MikeDeck It is, I had to look at the source.
    – mgorven
    Feb 4 '13 at 19:12

Looks like you can do this now

  - default
  - name: jdoe
    gecos: John Doe
      - ssh-rsa ...
  - name: jroe
    gecos: Jane Roe
      - ssh-rsa ...

from https://cloudonaut.io/avoid-sharing-key-pairs-for-ec2/

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.