Back to Top

Deploy CoreOS VM with ssh-keys

We will use Ubuntu here as an example.

  • 1. Install cloudmonkey:

apt-get install python-pip

pip install --upgrade pip

pip install cloudmonkey

  • 2. Then create config file for cloudmonkey:

mkdir .cloudmonkey

cat <<'EOF' > .cloudmonkey/config

[core]

profile = ssc

asyncblock = true

paramcompletion = true

history_file = /root/.cloudmonkey/history

log_file = /root/.cloudmonkey/log

cache_file = /root/.cloudmonkey/cache

 

[ui]

color = true

prompt = >

display = default

 

[swiss1]

url = https://swiss1.safeswisscloud.ch:443/client/api

username = [YOUR USER NAME]

apikey = [YOUR API KEY]

secretkey = [YOUR SECRET KEY]

timeout = 3600

expires = 600

domain = /[YOUR DOMAIN]

signatureversion = 3

verifysslcert = true

password = [YOUR PASSWORD]

 

[swiss2]

url = https://swiss2.safeswisscloud.ch:443/client/api

username = [YOUR USER NAME]

apikey = [YOUR API KEY]

secretkey = [YOUR SECRET KEY]

timeout = 3600

expires = 600

domain = /[YOUR DOMAIN]

signatureversion = 3

verifysslcert = true

password = [YOUR PASSWORD]

EOF

  • 3. Then run cloudmonkey and type in the following commands:

3.1 First for swiss1

# cloudmonkey -p swiss1

Apache CloudStack  cloudmonkey 5.3.2. Type help or ? to list commands.

 

Using management server profile: ssc 

 

(ssc) > sync

274 APIs discovered and cached

(ssc) > 

3.2 Now add the ssh key

(ssc) > register sshkeypair name=my-ssh publickey='ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAuvwUV7YLiOpjJoNMeD3dNlcLVejDrYOK1yH9GGnpgL7QeuQ/8vltUSzS1D9IaDEpdRQS8MxkDQWH4zToh0HeqIGI5Y WrEQfSTl5ZhySWWRAid4/FN56KgsSK2A5KlHbQkXMpyKQooI96aCjVzDMB8pqhyhYyyDhnCYVuV9b0/qzuAX8E9S8dMwvrBrUaStWBNaDBpPvDibEAlQ465 GNVAHvsDRq4w9TYCHizHuvl1Idr67POm7eJcJYvbUel71VkEH/b7LaKRU1iQyWOmRb65ROjI3qLVu2DzbSRnKujIUye3ABoo/gjNH0zc/sYnMfEwFGESKsfJFbt 5sOV7tdiQ=='

 

3.3 Next deploy a VM containing the ssh key

(ssc) > deploy virtualmachine serviceofferingid=a0236e81-1152-4191-9f14-3fe322dc40c4 templateid=09e9b37e-9435-49c8-85b8-ee915c1bc155 keypair=my-ssh networkids=[YOUR_NETWORK_ID] name=my-coreos displayname=my-coreos zoneid=1d954519-907f-45c0-bd56-36b38ff6bbe4 

 

3.4 Use the same procedure for swiss2, but with different ids for zone, network, template and serviceoffering:

# cloudmonkey -p swiss2

Apache CloudStack  cloudmonkey 5.3.2. Type help or ? to list commands.

 

Using management server profile: ssc 

 

(ssc) > sync 

274 APIs discovered and cached

(ssc) > 

 

3.5 Add the ssh key

(ssc) > register sshkeypair name=my-ssh publickey='ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAuvwUV7YLiOpjJoNMeD3dNlcLVejDrYOK1yH9GGnpgL7QeuQ/8vltUSzS1D9IaDEpdRQS8MxkDQWH4zToh0HeqIGI5Y WrEQfSTl5ZhySWWRAid4/FN56KgsSK2A5KlHbQkXMpyKQooI96aCjVzDMB8pqhyhYyyDhnCYVuV9b0/qzuAX8E9S8dMwvrBrUaStWBNaDBpPvDibEAlQ465 GNVAHvsDRq4w9TYCHiz/Huvl1Idr67POm7eJcJYvbUel71VkEH/b7LaKRU1iQyWOmRb65ROjI3qLVu2DzbSRnKujIUye3ABoo/gjNH0zc/sYnMfEwFGESKsfJF bt5sOV7tdiQ=='

 

3.6 Now deploy a VM containing the ssh key

(ssc) > deploy virtualmachine serviceofferingid=1e0a3524-abcf-479d-8a8c-146d74c8e81b templateid=f0f96794-7904-4dab-828d-94bdd4401f5c keypair=my-ssh networkids=[YOUR_NETWORK_ID] name=my-coreos displayname=my-coreos zoneid=9e165259-d754-4704-9813-f235c4f613f7

 

 

NOTE: Replace the ssh key and network id with your own. You can also change the serviceoffering ID to suit your needs.

You are able to list your own networks with the following commands:

 

#For Swiss1

cloudmonkey -p swiss1 list networks filter=name,id

#For Swiss2

cloudmonkey -p swiss2 list networks filter=name,id

 

Similar for serviceofferings:

 

cloudmonkey -p swiss1 list serviceofferings filter=name,id

 

cloudmonkey -p swiss2 list serviceofferings filter=name,id

 

  • 4. Then it is possible to do port forward port 22 from a public IP in the VR to the newly created VM and to ssh with the keys without needing to type the password

ssh core@[YOUR_VMs_PUBLIC_IP]