binarypaladin

binarypaladin

Known_hosts, SFTPClient, and Erlang SSH

I’ve spent some time mucking around SFTPClient because, unfortunately, my line of work requires me to deal with SFTP as one of the main means of getting data from various dinosaurs.

One of the major headaches I have hit, and I don’t think it has anything to do with SFTClient so much as something going on with the underlying Erlang tools is… known_hosts. Our deployed environments have read-only file systems so whenever we add another source for SFTP, I need the fingerprint to be in a static known_hosts file. This is actually fine and desirable in many ways except…

When I get a fingerprint from using ssh-keyscan or just trying ssh or sftp and checking my own known_hosts I’ll have a domain name. Whenever I connect through SFTPClient I end up with an IP address.

This is… not great. I want the domain name, not the IP because if that changes… things break and I gotta update the file and deploy. (Also, I’m not asking for solutions to this issue. Most of it is beyond my control.)

Not only is my Erlang not great, I’m a pretty casual SSH’er. When I have to do anything complicated I’m probably following a guide given to me by IT or some online guide. So my ignorance could be totally at play. The thing is, I don’t know where the issue really lies. Is this an Erlang library thing? The way SFTPClient is using Erlang? Something with an ssh config?

If anyone is more expert in this than me, please help! Haha. I’m working toward expanding my knowledge here but the number of hours in a day are painfully finite.

Marked As Solved

binarypaladin

binarypaladin

As is tradition, reading the docs while not stressing and being in a hurry helped.

Thanks for, more or less, pointing me back to the documentation I had tried so hard to avoid deep-diving into.

add_host_key/4 and is_host_key/4 from the :ssh_client_key_api let me handle persisting the known hosts. Checking out the code in :ssh_file got me most of what I needed.

The only thing I haven’t dug deeper into is the situation with the IP address instead of a hostname. I don’t know if this related to what SFTPClient is doing or something inside Erlang. The code in :ssh_file certainly suggests non-IP address hostnames can happen.

When (if) I ever have time, I think I’m going to just drop SFTPClient entirely and use Erlang directly for this. One less dependency and I can’t even tell how actively maintained the former is.

Also Liked

Schultzer

Schultzer

Not the exactly fix that you wanted, but you can silently accept host and not save the host: ssh — OTP 29.0.2 (ssh 6.0.1)

Then you avoid the issue with read only fs, and since you know the domain and likely use some form of authentication, then that is good enough. The known_host file is mostly to avoid domain hijacking, but in your case it’s the reverse.

I also want to add, if you’re concerned about MITM attacks here, don’t. You, your infrastructure provider and your clients would have bigger problems then.

Last Post!

Schultzer

Schultzer

Use inet — OTP 29.0.2 (kernel 11.0.2) or the reverse to lookup hostname or ip.

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement