Score:0

Unable to SSH into server when using passwordless SSH keys

bt flag

This is probably an idiotic question, but I'll try and provide as much information as possible. If you need any extra details, then please let me know.

I have a Mac running Ventura and an AlmaLinux virtual machine running in VMWare Fusion Pro 13. AlmaLinux is version 9.1.

First I created my SSH keypair on macOS:

ssh-keygen -t ed25519 -f ~/.ssh/localdevonly

Then I made a config file in ~/.ssh/config also on macOS.

That file contains this:

Host localdev
    HostName 172.16.91.137
    User simon
    IdentityFile ~/.ssh/localdevonly

Then I uploaded the SSH public key:

scp ~/.ssh/localdevonly.pub simon@localdev:/home/simon/.ssh/authorized_keys

I changed the permissions on the authorized_keys file in AlmaLinux:

chmod 444 ~/.ssh/authorized_keys

Then I added the SSH key to the SSH Agent on macOS:

ssh-add ~/.ssh/localdevonly

Then I try to login from macOS:

ssh localdev -v

Which gives the following output:

OpenSSH_9.0p1, LibreSSL 3.3.6
debug1: Reading configuration data /Users/simon/.ssh/config
debug1: /Users/simon/.ssh/config line 1: Applying options for localdev
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 172.16.91.137 [172.16.91.137] port 22.
debug1: Connection established.
debug1: identity file /Users/simon/.ssh/localdevonly type 3
debug1: identity file /Users/simon/.ssh/localdevonly-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.0
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.7
debug1: compat_banner: match: OpenSSH_8.7 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 172.16.91.137:22 as 'simon'
debug1: load_hostkeys: fopen /Users/simon/.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
debug1: kex: host key algorithm: ssh-ed25519
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: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:bVk7Pm91A5qGjVI+6o+nAo8+4qm+sIyrgmZiwJhH1Dw
debug1: load_hostkeys: fopen /Users/simon/.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 '172.16.91.137' is known and matches the ED25519 host key.
debug1: Found key in /Users/simon/.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: get_agent_identities: bound agent to hostkey
debug1: get_agent_identities: agent returned 3 keys
debug1: Will attempt key: /Users/simon/.ssh/localdevonly ED25519 SHA256:CsSaNoNXrF/Fdxfiaj8NR1b1TC2/lRy7aXpyt7Bm9sk explicit agent
debug1: Will attempt key: [email protected] ED25519 SHA256:ADJnS0Xnk/Al1TJrahM8AWDXKhrapjwxhz9P17z3cUw agent
debug1: Will attempt key: MuzikStrm ED25519 SHA256:hu4rJT60Pk1Jx9IT73wlmrLPIg6ya3In1JdNFkIVlso agent
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,[email protected],ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected]>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/simon/.ssh/localdevonly ED25519 SHA256:CsSaNoNXrF/Fdxfiaj8NR1b1TC2/lRy7aXpyt7Bm9sk explicit agent
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Offering public key: [email protected] ED25519 SHA256:ADJnS0Xnk/Al1TJrahM8AWDXKhrapjwxhz9P17z3cUw agent
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Offering public key: MuzikStrm ED25519 SHA256:hu4rJT60Pk1Jx9IT73wlmrLPIg6ya3In1JdNFkIVlso agent
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Next authentication method: keyboard-interactive
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey,keyboard-interactive).

I have no idea how I can fix this problem. I'm stumped. If someone could point me in the right direction I would really appreciate it!

diya avatar
la flag
In general: you can’t debug server issues from the client alone. Check the logs on the server. Increase verbosity if necessary
dave_thompson_085 avatar
jp flag
You need to ensure restricted permissions for both file `.ssh/authorized_keys` and dir `.ssh` on the server.
Cromulent avatar
bt flag
@dave_thompson_085 it was the wrong permissions on the .ssh folder! Thank you so much!
Score:0
it flag

On the server, /var/log/secure would have flagged that the authorized_keys file or ~/.ssh dir wasn't accepted due to permissions (mode) or ownership.

Score:0
pl flag

Please, set the following permissions and try again:

chmod 600 ~/.ssh/authorized_keys

chmod 700 ~/.ssh

And it is better to use ssh-copy-id instead of scp command.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.