Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang :ssh authentication error. How to connect to ssh using identity file

Tags:

erlang

elixir

I'm getting an authentication error when trying to connect ssh host.

The goal is to connect to the host using local forwarding. The command below is an example using drop bear ssh client to connect to host with local forwarding.

dbclient -N -i /opt/private-key-rsa.dropbear -L 2002:1.2.3.4:2006 -p 2002 -l
test_user 11.22.33.44

I have this code so far which returns empty connection

ip = "11.22.33.44"
user = "test_user"
port = 2002

ssh_config = [
  user_interaction: false,
  silently_accept_hosts: true,
  user: String.to_charlist(user),
  user_dir: String.to_charlist("/opt/")
]
# returns aunthentication error
{:ok, conn} = :ssh.connect(String.to_charlist(ip), port, ssh_config)

This is the error Im seeing

Server: 'SSH-2.0-OpenSSH_5.2'
Disconnects with code = 14 [RFC4253 11.1]: Unable to connect using the available authentication methods
State = {userauth,client}
Module = ssh_connection_handler, Line = 893.
Details:
  User auth failed for: "test_user"

I'm a newbie to elixir and have been reading this erlang ssh document for 2 days. I did not find any examples in the documentation which makes it difficult to understand.

like image 565
Sheshank Kodam Avatar asked Oct 18 '25 04:10

Sheshank Kodam


1 Answers

You are using non-default key name, private-key-rsa.dropbear. Erlang by default looks for this set of names:

From ssh module docs:

  • Optional: one or more User's private key(s) in case of publickey authorization. The default files are
    • id_dsa and id_dsa.pub
    • id_rsa and id_rsa.pub
    • id_ecdsa and id_ecdsa.pub`

To verify this is a reason, try renaming private-key-rsa.dropbear to id_rsa. If this works, the next step would be to add a key_cb callback to the ssh_config which should return the correct key file name.

One example implementation of a similar feature is labzero/ssh_client_key_api.

like image 98
Nic Nilov Avatar answered Oct 21 '25 10:10

Nic Nilov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!