jaimeiniesta
I’m using sftp_ex to connect to an sFTP server, authenticating with my SSH key, and it works out of the box - provided the key is at .ssh/id_rsa and that .ssh/id_rsa.pub has been set up on the remote server.
But, I don’t know how to specify a different SSH key. For example if my key is at .ssh/custom_key how can I use this one?
Also, in my app I’m going to have the private key as an ENV variable, how can I use that instead of having the file at .ssh?
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #ai
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming










Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
easco
The first thing that strikes my eye is that the documentation for
SftpEx.connectsaysIf you look at that documentation then you can pass the type client_options().
client_options()in turn includes the type common_option() andcommon_option()include key_cb_common_option()That is the “key callback” options and seems to let you specify a module that follows the ssh_client_key_api. As near as I can tell that means you have to create a module that has a method called
user_keythat accepts an algorithm specification (like RSA, DSA, etc) and returns the private key that corresponds to that.You could create such a module. In the implementation of
user_keyyou could take the value of the key in the environment variable and put it into the format recognized by Erlang’s:public_keymodule. In a recent case I had the key inpemformat and I had to combine:public_key.pem_decodeand:public_key.pem_entry_decodeto extract a key frompemdata.user_keywould return that key.Then you pass the name of that module to the
SftpEx.connectfunction as[key_cb: YourModule]Now… having said all that, I just got that by reading the docs… I haven’t actually tried it.
jaimeiniesta
Thanks for your help @easco - for the record we found an easier solution, by using the
user_diroption to specify an alternative directory where theid_rsaprivate key is stored in the server where we connect from.We also found that when connecting it tried to write the
known_hostsfile in that directory, so you can either give this directory write permissions, or pre-populate it with this file so it doesn’t need to be updated.OvermindDL1
For note, if you don’t want it to generate a
known_hostsfile then if you pass in the hosts public keys in the proper option (silently_accept_hostsor something like that) then it will only use those, but it will not accept any others either, which can be quite good for security.jrissler
In case anyone comes across this in the future - I spent a few minutes to figure this out, @easco’s solution works great - here’s how it looks:
Otherwise - followed his idea pretty closely. For brevity, didn’t post include error handling, but this is what it would look like: sftp_client/lib/sftp_client/key_provider.ex at 215ff5bcaeae6ebdd77c04d619c33a20c55eb12c · tlux/sftp_client · GitHub
thbar
Hi Jaime! By any chance, did you ultimately end up using an ENV variable successfully for this?
I would be potentially interested, to e.g. deal with read-only GitHub deploy keys.
Thanks!
jaimeiniesta
Hey Thibaut!
No, we finally chose the
user_diroption instead, see my reply on Feb '19 aboveGenericJam
Just to fill in a few more blanks here. If you use @jrissler 's gist you need to tie it into the rest of your code.
Also, bonus pro tip on
SftpExand the underlying Erlang code. You need to first open the connection which will create the file on the SFTP server and give you back ahandlewhich you can then use as your file reference after that. Then you can stream, upload, download, etc. The docs for this lib are wrong as per my usage.