Search code examples
azureubuntusshvirtual-machineazure-cli2

ssh to azure-vm after building from image


I have created an image from an existing ubuntu-vm. After that I have created some vms based on that image using azure-documentation. The command I used in the CLI for creating the VMs was

az vm create --resource-group <groupname> --name <vmname>
--image <imagename> --admin-username <adminname>
--ssh-key-value ~/.ssh/id_rsa.pub

Created VMs are just fine, but I can't connect to them via ssh. When I

ssh -v <adminname>@IP

I get

mongo1@Mongo1:~$ ssh -v [email protected]
OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 10.0.0.5 [10.0.0.5] port 22.
debug1: Connection established.
debug1: identity file /home/mongo1/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mongo1/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mongo1/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mongo1/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mongo1/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mongo1/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mongo1/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/mongo1/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4p1 Ubuntu-10
debug1: match: OpenSSH_7.4p1 Ubuntu-10 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 10.0.0.5:22 as 'paunix'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected]
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:SJnFJndqGBMkZB/Nq81uolEjv7tbMZ404S6424PIoSw
debug1: Host '10.0.0.5' is known and matches the ECDSA host key.
debug1: Found key in /home/mongo1/.ssh/known_hosts:6
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/mongo1/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/mongo1/.ssh/id_dsa
debug1: Trying private key: /home/mongo1/.ssh/id_ecdsa
debug1: Trying private key: /home/mongo1/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).

I'm quit new to this hole azure-unix-stuff, so I can only assume that it has something to do with the 'ssh-key-value' in the command for creating the vms... what I must do to ssh to the vms? Oh, and OS of the vms is Ubuntu-16.04...


Solution

  • According to your error log, you don't have private key in ~/.ssh.

    Please use ssh-keygen to create a new pair of key and use Azure CLI to create new VM again.

    If you know your private location. You could use ssh -i <path/id_rsa> user@ip to ssh your VM.

    Another solution when you create VM, using --generate-ssh-keys replace --ssh-key-value ~/.ssh/id_rsa.pub.