Created
June 22, 2019 09:43
-
-
Save pmeinhardt/a39494d43f6acf606fc7249a3fe2cb50 to your computer and use it in GitHub Desktop.
escript to try out ssh-agent support in OTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env escript | |
receive_data() -> | |
receive | |
{ssh_cm, _, {closed, __}} -> | |
io:fwrite("Channel closed~n", []); | |
{ssh_cm, _, Msg} -> | |
io:fwrite("SSH message: ~p~n", [Msg]), | |
receive_data() | |
after 1000 -> | |
io:fwrite("Timed out", []) | |
end. | |
main(_) -> | |
ok = ssh:start(), | |
% Connect using original code (password for key) | |
% {ok, Conn} = ssh:connect("127.0.0.1", 22, [{user, "dev"}, {auth_methods, "publickey"}, {user_interaction, true}, {silently_accept_hosts, true} , {rsa_pass_phrase, "pass!"}]), | |
% Connect using new "ssh_file_with_agent" module (no password for unlocking key) | |
{ok, Conn} = ssh:connect("127.0.0.1", 22, [{user, "dev"}, {auth_methods, "publickey"}, {user_interaction, false}, {silently_accept_hosts, true}, {key_cb, {ssh_file_with_agent, []}}]), | |
{ok, Chan} = ssh_connection:session_channel(Conn, 1000), | |
success = ssh_connection:exec(Conn, Chan, "whoami", 1000), | |
receive_data(), | |
ok = ssh_connection:close(Conn, Chan), | |
ok = ssh:close(Conn). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment