Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Inject ssh public key into multipass vm

Example of usage :

./inject_pubkey.sh myvmname
#!/bin/bash
if [ $# -eq 0 ]
then
echo "I need the instance name."
exit
fi
INSTANCE_NAME=$1
multipass copy-files $INSTANCE_NAME:/home/ubuntu/.ssh/authorized_keys .
cat ~/.ssh/id_rsa.pub >> authorized_keys
multipass copy-files authorized_keys $INSTANCE_NAME:/home/ubuntu/.ssh/authorized_keys
echo "authorized_keys in the vm '$INSTANCE_NAME' are now :"
multipass exec $INSTANCE_NAME -- cat /home/ubuntu/.ssh/authorized_keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment