Automating Multiple User Account Creation in AWS EC2 Ubuntu instance

Viewed 18

I have an EC2 Ubuntu instance and I want to make around 100 accounts on it. I have generated all the necessary key-pairs using a Python Script. Now the challenge is to send the public keys to the corresponding user directories in an automated manner. I am on a Windows machine so ssh-copy-id does not seem to work and I cannot use that in a bash script.

Does anyone know the best way to tackle this? Any help would be appreciated.

1 Answers

Just do what ssh-copy-id does.

  • SFTP or SSH to the host (e.g. using Paramiko).
  • Create .ssh folder with right permissions, if it does not exist yet.
  • Create authorized_keys with right permissions, if it does not exist yet.
  • Append your public key to it.

Btw, googling "ssh-copy-id in python" reveals that there's Python implementation of ssh-copy-id:
https://pypi.org/project/sshcopyid/

Related question of Super User:
Command to copy client public key to Windows OpenSSH SFTP/SSH server authorized keys file

Related