Skip to content

Instantly share code, notes, and snippets.

@brahimmachkouri
Last active September 3, 2023 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brahimmachkouri/ae86f8b45641e5813f9f58e370967ade to your computer and use it in GitHub Desktop.
Save brahimmachkouri/ae86f8b45641e5813f9f58e370967ade to your computer and use it in GitHub Desktop.
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 :"
multipass ls
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