SSH Client failed to connect using private key

I’m trying connect to ssh server using custom location (not in ~/.ssh) private key

key =!("/private/tmp/.ssh/id_rsa")
known_hosts =!("/private/tmp/.ssh/known_hosts")

cb =
    identity: key,
    known_hosts: known_hosts,
    silently_accept_hosts: true

# IO.inspect(cb)

context =
    port: 22,
    user: "username",
    key_cb: cb,
    #password: "pass",
  ), "whoami")

But get result:

16:34:28.579 [notice] Erlang SSH :client version: 5.0.1 (OpenSSL 1.1.1s  1 Nov 2022).
Peer server version: ~c"SSH-2.0-OpenSSH_9.2p1 Debian-2"
Peer address:
Disconnects with code = 14 [RFC4253 11.1]: Unable to connect using the available authentication methods
State = {userauth,client}
Module = ssh_fsm_userauth_client, Line = 96.
  User auth failed for: "username"

I also try using :ssh.connect but got same result.


  • I can connect using password authentication
  • I can connect with key using ssh cli ssh username@host -i /private/tmp/.ssh/id_rsa