[SOLVED] How todo I provide ssh_public_key the correct way

I am new to OpenNebula and I am able to run my machines on KVM (migrated from VirtualBox). So far so good.
Now I wanted to try a template provided on the marketplace, but I can’t login.
I tried the following under [SOLVED] How to substitute the value SSH_PUBLIC_KEY with the output of cat ~/.ssh/id_rsa.pub but it still does not work.

What I did (without success):
Imported the Debian 8.2 KVM using Marketplace in Sunstone.
Added into the template my public key of three different users:
First, my local user of my client. After that, I added the public key of a user root. This also does not work so I added the public key of oneadmin (see link above).

Starting the virtual machine I am unable to ssh and also unable to login without passwort using vnc (and unable to login using ssh).

In the documentation I am only to find “provide the public key”, but what public key I have to use? Do I have to add in the template into the context field?

Tried other images of the marketplace, but the same problem.

Using VNC, the machine wants to have a username and password.

Which public rsa key of what user I have to paste where?

Thank you very much for your help!


Hi Daniel,

There are various places where you can add your public key:

in your sunstone user’s settings:
Settings --> Info tabb --> ‘Public SSH key’ box
in you VM template:
Selecet VM template -> Update --> Context tab --> Public Key (Add ssh contextualization must be ticked)

For SSH to work you must enable the networking by selecting a network in the network tab in the template wizard after you import image from the marketplace.

To set a password for the VM from the market place some more preparation is needed. For example to set the root password on VM instantiation:

Create the following text file:


if [ -n "$ROOT_PASSWORD" ]; then
    echo "root:$ROOT_PASSWORD" | chpasswd

Then upload it in the Files & Kernels. Set its name to like set-root-password.sh

Then in the VM template -> Context --> Configuration add User input with the following attributes:
Type: password
Description: any description (optional?)

Then select Files (next under Configuration) and select the imported script.

In the Init scripts field type the file’s name - same as the one you set in Files & Kernels.

With the above configuration in the VM instantiation dialog There will be prompt to set the password for root. (Somewhere on the bottom of the page)

Type an password, start the VM and use it to login in the VNC console.

I hope this crash course will help.

Kind Regards,
Anton Todorov

1 Like

Hello Anton,

thank you very much for your detailed description.

Both ways are working now (it was the public ssh key of my user I am working within sunstone, wich let me login now using ssh). It also works like a charm by providing the password script.
I decided to use the “password method”, because all my other virtual machines, I moved from VirtualBox, were set up using passwords, so the same behaviour will be the best way :smile:

Thanks again and have a nice evening!


Hi All,
I added the public ssh key to the oneadmin in sunstone. But when I deploy a VM e.g. the Debian 8.2 kvm the template holds the public key. Never the less a root login via the vnc doesn’t work.
What I’m doing wrong.

When I try to set the password, I have an error when I instantiate the VM:

[TemplateInstantiate] Error allocating a new virtual machine. Error parsing: set-root-password.sh. syntax error, unexpected RSTRING, expecting VARIABLE at line 1, columns 1:21

Thanks in advance for any direction you could provide me with.


the ssh public key is used to login to the VM via the SSH protocol. For VNC console the root password must be set via the contextualization.

please add some more info, like

onetemplate show <templateID> --xml
onevm show <vmID> --xml    (but please strip the PCI info -it is a lot and not related to the issues)

Some more info - like the version of opennebula, what steps are completed, configurations, etc. It is hard to guess what is the overall setup and where the problems could be…

Kind Regards
Anton Todorov

Hi Anton,
now I managed it or moreover I understand how it works. The passwordless login for root only works via the frontend machine as oneadmin user.
So on the frontend machine:

  1. su oneadmin
  2. ssh@192.x.x.x (new machine)
    Then I can admin this machine.
    Thank you for your help.

Thank you for your answer Anton.
I am testing OpenNebula 4.14.0 on a dedicated server.

Here is my template:


For my VM I can’t provide with anything as instanciation fails…

Hi @vialcollet,

I would like to suggest to update OpenNebula to 4.14.2 which is mostly bug-fix release and solves the bug that you are hitting.

Kind Regards,
Anton Todorov

Thanks for your help @atodorov_storpool. I will do so and report the result.
Thanks again!

Ok this is now working fine.
Thanks a lot.

Hi all, i want to login to the centos kvm downloaded from the marketplace, and so i copy the id_rsa.pub in the contextualization of the template but when the vm is running it require an username and password again…what i’m doing wrong. thank you very much for any help.

Hi Florin_Tanasache1, the centOS image will have they ssh key of the user who as far as i know owns the VM. once you place the ssh key in the contextualization of the VM make sure you shut it down and start it again since as far as i know it needs to be injected during bootup.

When this is done you need to ssh to the centos KVM vm from the machine that has the private key associated with the public key that you just placed in the VM via the contextualization. This machine is most probably your front-end. Then #ssh root@IP-of-the-centos-KVM-VM

thanks for your response, but it does not work. Moreover i cannot ping the vm centos-kvm from my frontend (in my case the frontend is the host having the vms). can i use vnc to do this? sorry, but i’m newbie with opennebula

An ssh key as the name implies is used only by the SSH protocol. When you use VNC that is a console session, just like having a keyboard and a mouse attached to a physical machine.

1 Like

ok, now after i changed the network interface i can ssh to the centos and a have access to the root of machine. thank you very much. However, if i want to use the vnc console what have i do? which are the credentials in order to access the machine?

The root password has public key authentication enabled so the easiest way would be:

1- SSH to the vm using the root username

Create a new user by:

2- useradd centos

3- passwd centos à type a password here

4- try using this user via the console (VNC)

the steps above are not specific to OpenNebula, but mainly Linux administration, I am just saying to make sure that you understand that this is not an OpenNebula “problem”

1 Like

yes, i know, but i thought that vnc could work differently. Many thanks!

When I try to set the password, I have an error when I instantiate the VM:.