Ssh – Mobaxterm – Permission Denied (Publickey)

public-keyssh

Am having some issues connecting to a linux instance in AWS via mobaxterm.
I get the following error when trying to SSH on to the server;

─
[2018-02-16 10:07.57]  ~
[bunde.DESKTOP-A0APQ1T] ➤ ssh -v -i "XYZ.pem" servername.eu-west-2.compute.amazonaws.com
OpenSSH_7.1p2, OpenSSL 1.0.1g 7 Apr 2014
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to servername.eu-west-2.compute.amazonaws.com [x.x.x.x] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /var/keys/.10996.ssh type -1
debug1: key_load_public: No such file or directory
debug1: identity file /var/keys/.10996.ssh-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to servername.eu-west-2.compute.amazonaws.com:22 as 'bunde'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-sha1 zlib@openssh.com
debug1: kex: client->server aes128-ctr hmac-sha1 zlib@openssh.com
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256: ...
debug1: Host 'servername.eu-west-2.compute.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in /home/mobaxterm/.ssh/known_hosts:1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: pubkey_prepare: ssh_fetch_identitylist: agent refused operation
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /var/keys/.10996.ssh
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
**Permission denied (publickey).**

Any ideas?
I've tried playing around with file permissions (I know from my mac the keys have to be well locked down), but any changes dont seem to impact the error I am getting.

Best Answer

It looks like your problem is in file permissions, could you check via mobaxterm that the key located in the folder that your are trying to run ssh command?

Run a ls -lh from Mobaxterm console and check file XYZ.pem exists with owner and group of the user that is running mobaxterm, besides with permissions 600 (-rw-------).

I'm not an expert in MAC, although, I'm pretty sure it has an ssh client by default, look at this link