I followed How to Capture an Image of a Virtual Machine Running Linux to capture a VM image, after installing the packages I wanted on top of Ubuntu 12.04 LTS. I turned off the machine following a waagent -deprovision
and Captured the image.
When I had created the first VM (which I later captured), I specified a certificate file key1.pem
.
When I created a new VM from the My Images image, I specified a certificate file key2.pem
.
When I attempted to connect to the new VM, I received the message Permission denied (public key).
. To connect, I used ssh -i ssh/key2 -p myport [email protected]
.
What's wrong? Are there special steps needed to use a different key than was used in the template image? Is this a bug?
At first glance it seems you're trying to deploy a .pem file as the public key of a SSH key-pair in
~azureuser/.ssh/authorized_keys
so you can use key-based authentication rather then password based ssh login, is that the case?I normally associate PEM files with SSL certificates and you should note, in the words of the man page, that SSH certificates are a different, and much simpler, format to the X.509 certificates used in SSL. So using SSL certificates instead of SSH keys/certificates is going to fail.
Normally a private use SSH key-pair is created with
ssh-keygen -b 2048 -t rsa -f .ssh/mykey
which will create 2048 bit RSA private key file~/.ssh/mykey
and the corresponding public key~/.ssh/mykey.pub
. That public key needs to be deployed to~azureuser/.ssh/authorized_keys
Make sure that on the both your client and the server the
~/.ssh
directory is only accessible to the owner withchmod 0700
and all the keyfiles are only readable for their owner i.e.chmod 0600
.Further debugging ssh can be done from the client with
ssh -v -i ssh/mykey -p myport [email protected]
or even more verbosely with-vv
.