Execute ssh command with private key

[FONT=times new roman]I am trying to execute ssh command with a private key for the supplied username.
Somehow it fails and revert to trying password.

build@buildserver:~> ssh -v -i private.key build@repo.company.com
OpenSSH_6.2p2, OpenSSL 0.9.8j-fips 07 Jan 2009
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug1: Connecting to repo.company.com [xxx.xxx.xxx.xxx] port 22.
debug1: Connection established.
debug1: identity file private.key type -1
debug1: identity file private.key-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1
debug1: match: OpenSSH_6.6.1 pat OpenSSH*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00 [MD5]
debug1: Host 'mcorerepohost.spacetec.no' is known and matches the ECDSA host key.
debug1: Found key in /home/build/.ssh/known_hosts:12
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Trying private key: private.key
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Next authentication method: keyboard-interactive


The output shows that key was tried and failed. In this cause you would need to view the logs on the destination machine.

You can also increase the verbosity of the debugging on your end by going from -v to -vvv.

I would also suggest you check the private and public key files to ensure they have the same md5 otherwise you will have issues.
Command: ssh-keygen -l -f {key}

Check the ownership and permissions of the key. The default is to keep it in .ssh with 750 folder permissions and 600 for key permissions.

On the receiving system in the .ssh folder(750 permissions) the public key should be in “authorized_keys” with 600 permissions.

You can use the following SDB to check whether your setup is correct. Although it’s ancient, to my eye the only significant thing that needs to be updated is to substitute the rc commands with systemd commands to stop/start the sshd service