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

7,979

Solution 1

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

Solution 2

Looks like you can do this now

#cloud-config
users:
  - default
  - name: jdoe
    gecos: John Doe
    ssh-authorized-keys:
      - ssh-rsa ...
  - name: jroe
    gecos: Jane Roe
    ssh-authorized-keys:
      - ssh-rsa ...

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

Share:
7,979

Related videos on Youtube

Mark McClelland
Author by

Mark McClelland

I'm a Java developer with exposure to several other languages and platforms including .Net, Ruby/Rails, and Flex. I've worked on a variety of types of projects ranging from short term individual work to very large scale, multi-phase projects using multiple large development teams. I've developed both back end message processing systems as well as end user facing webapps. I most enjoy working on smaller teams with other talented developers in an environment where we are responsible for the entire application stack end to end. I'm lucky enough to have a great job that I enjoy leading a product development team at a small company in Dallas, but I'm always interested in hearing about other opportunities. Feel free to take a look at my CV on Stack Overflow Careers.

Updated on September 18, 2022

Comments

  • Mark McClelland
    Mark McClelland over 1 year

    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?

  • Mark McClelland
    Mark McClelland over 11 years
    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.
  • mgorven
    mgorven over 11 years
    @MikeDeck It is, I had to look at the source.