MAC Monterey 12.1 SSH to AWS Lightsail Ubuntu does not work

Here is a strange one for me (maybe not for you).


I have an AWS UBUNTU server and if I use Putty on my Windows PC I can logon no issues using my private key. Use the same private key and I get this:


user@MacBook-Air aws % ssh -v -i certfile.pem ubuntu@x.x.x.x 

OpenSSH_8user.6p1, LibreSSL 2.8.3

debug1: Reading configuration data /etc/ssh/ssh_config

debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files

debug1: /etc/ssh/ssh_config line 54: Applying options for *

debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling

debug1: Connecting to x.x.x.x [x.x.x.x] port 22.

debug1: Connection established.

debug1: identity file certfile.pem type -1

debug1: identity file certfile.pem-cert type -1

debug1: Local version string SSH-2.0-OpenSSH_8.6

debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.10

debug1: compat_banner: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.10 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002

debug1: Authenticating to x.x.x.x:22 as 'ubuntu'

debug1: load_hostkeys: fopen /Users/user/.ssh/known_hosts2: No such file or directory

debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory

debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory

debug1: SSH2_MSG_KEXINIT sent

debug1: SSH2_MSG_KEXINIT received

debug1: kex: algorithm: curve25519-sha256@libssh.org

debug1: kex: host key algorithm: ssh-ed25519

debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none

debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none

debug1: expecting SSH2_MSG_KEX_ECDH_REPLY

debug1: SSH2_MSG_KEX_ECDH_REPLY received

debug1: Server host key: ssh-ed25519 SHA256:anhe7i/6tDv5bjACzsiP7/k1VLJPRoKTVRKAcOW+lTA

debug1: load_hostkeys: fopen /Users/user/.ssh/known_hosts2: No such file or directory

debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory

debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory

debug1: Host 'x.x.x.x' is known and matches the ED25519 host key.

debug1: Found key in /Users/user/.ssh/known_hosts:1

debug1: rekey out after 134217728 blocks

debug1: SSH2_MSG_NEWKEYS sent

debug1: expecting SSH2_MSG_NEWKEYS

debug1: SSH2_MSG_NEWKEYS received

debug1: rekey in after 134217728 blocks

debug1: Will attempt key: /Users/user/.ssh/certfile.pem RSA SHA256:DRJHJjr9kBUqBefuXxXMJsxrysdhoTvzhqurBXH1d4g agent

debug1: Will attempt key: certfile.pem explicit

debug1: SSH2_MSG_EXT_INFO received

debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>

debug1: SSH2_MSG_SERVICE_ACCEPT received

debug1: Authentications that can continue: publickey

debug1: Next authentication method: publickey

debug1: Offering public key: /Users/user/.ssh/certfile.pem RSA SHA256:DRJHJjr9kBUqBefuXxXMJsxrysdhoTvzhqurBXH1d4g agent

debug1: Authentications that can continue: publickey

debug1: Trying private key: certfile.pem

debug1: Authentications that can continue: publickey

debug1: No more authentication methods to try.

ubuntu@x.x.x.x: Permission denied (publickey).


I am lost so any help is appreciated. I suspect it is a permissions issue. As I said before using the same private key in Putty on a Windows machine there is no issue.


Posted on Feb 15, 2022 4:45 PM

Reply
Question marked as Top-ranking reply

Posted on Feb 16, 2022 2:02 PM

@barberlives123

The user is NOT using PuTTY on the Mac. The user was using PuTTY on Windows, and wanted to know why they could not use macOS Terminal and the ssh command to make the same connection that worked on Windows.


@MBOHARAKBC

You need to convert your PuTTY keys over to the OpenSSH ssh-keygen format.

Google search for: "Converting PuTTY private keys to OpenSSH format"


Similar questions

6 replies
Question marked as Top-ranking reply

Feb 16, 2022 2:02 PM in response to MBOHARAKBC

@barberlives123

The user is NOT using PuTTY on the Mac. The user was using PuTTY on Windows, and wanted to know why they could not use macOS Terminal and the ssh command to make the same connection that worked on Windows.


@MBOHARAKBC

You need to convert your PuTTY keys over to the OpenSSH ssh-keygen format.

Google search for: "Converting PuTTY private keys to OpenSSH format"


Feb 17, 2022 1:56 PM in response to MBOHARAKBC

...
debug1: Offering public key: /Users/user/.ssh/certfile.pem RSA SHA256:DRJHJjr9kBUqBefuXxXMJsxrysdhoTvzhqurBXH1d4g agent
debug1: Authentications that can continue: publickey
debug1: Trying private key: certfile.pem
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
ubuntu@x.x.x.x: Permission denied (publickey).


Ubuntu has rejected your connection. You are now going to have to see if Ubuntu has indicated why it rejected the private PEM key.


You might need to modify the /etc/ssh/sshd_config file

LogLevel DEBUG3


On Ubuntu check 'man ssh' to see if it uses 'kill -HUP <pid>' to get the sshd daemon to re-read its config file. Or just reboot the Ubuntu system.


Remember to change the 'LogLevel' back when you are done testing. I've seen strange things happening to ssh if LogLevel is left at DEBUG3 levels.


The ssh messages should show up in either

/var/log/messages

or

/var/log/secure



The other option is to create a new ssh-keygen key and just put the .pub into your Ubuntu's user account .ssh/authorized_keys file.


I know you said AWS, so I'm not sure if there are other requirements that has you using the private key PEM certificate.

Feb 17, 2022 2:14 PM in response to MBOHARAKBC

MBOHARAKBC wrote:

I have an AWS UBUNTU server and if I use Putty on my Windows PC I can logon no issues using my private key. Use the same private key and I get this:

As BobHarris suggested, just create a new public/private key pair for your Mac and add the public key to the authorized_keys.


I use AWS Lightsail all the time and it works fine.


Note that you will have to copy your AWS root keys to your Mac if you want to login as root. They should work fine.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

MAC Monterey 12.1 SSH to AWS Lightsail Ubuntu does not work

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.