1

I need to start an SSH connection in my app which requires a username and password. The username is constant so can be hardcoded, but I want the password to be hidden (similar to read -s pass in bash).

I tried doing this with io:read, io:fread, io:read_line, io:get_chars, and even os:cmd("read -s pass") but it seems they always break from the code and only interact in shell:

===> Verifying dependencies...
===> Analyzing applications...
===> Compiling app
Erlang/OTP 24 [erts-12.2.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

Eshell V12.2.1 (abort with ^G)
.
.
.    app init code......
.
Enter SSH pass: abc.
(node@comp)1>
(node@comp)1>      normal shell, app waiting to continue
(node@comp)1>

Am I missing something? Is there another way to get user input to the app? should I just use the .ssh hashed passwords? If so, How?

halfway258
  • 115
  • 13
  • This is not an answer to this question, but it did fix my issue (for now): [automate ssh login with password](https://serverfault.com/questions/241588/how-to-automate-ssh-login-with-password) – halfway258 Jan 01 '23 at 09:13

1 Answers1

0

To suppress the echo you can use the hidden io:get_password function.

Password = io:get_password().

[Edit] Based on your feedback this doesn't solve the whole problem.

dynamicbutter
  • 311
  • 1
  • 5
  • Please read [answer] and [edit] your answer to contain an explanation as to why this code would actually solve the problem at hand. Always remember that you're not only solving the problem, but are also educating the OP and any future readers of this post – chrslg Jan 11 '23 at 00:46
  • Huh I didn't know this was a function, it's not in the doc. Anyway, same thing happens, password is still visible in shell and the app pauses. – halfway258 Jan 12 '23 at 08:13
  • My bad, this is a [known bug](https://github.com/erlang/otp/issues/4337). There are some workarounds suggested in [this thread](https://stackoverflow.com/questions/37720961/elixir-or-erlang-prompt-for-password-with-hidden-input) but they don't look very appealing to me. – dynamicbutter Jan 12 '23 at 17:53