[erlang-questions] scp subsystem

Stefan Jahn stefan@REDACTED
Tue Mar 19 15:12:40 CET 2013


Hello!

On Tue, March 19, 2013 3:01 pm, Ingela Andin wrote:
> Hi!
>
> 2013/3/19, Stefan Jahn <stefan@REDACTED>:
>> dear erlang'ers,
>>
>> after reading some documentation on ssh otp system I ended up with:
>>
>>     ssh:daemon({0,0,0,0}, 45678, [{pwdfun, fun auth/2},
>> %% create server keys:
>> %% ssh-keygen -f /tmp/ssh/ssh_host_rsa_key -N '' -t rsa
>> %% ssh-keygen -f /tmp/ssh/ssh_host_dsa_key -N '' -t dsa
>> 				  {system_dir, "/tmp/ssh"},
>> 				  {user_dir, "/tmp/ssh"},
>> %				  {ssh_cli,{ssh_cli, {ssh_scpd, []}}},
>> 				  {auth_methods, "keyboard-interactive,password"},
>> 				  {subsystems, [
>> 						ssh_scpd:subsystem_spec([])
>> %						ssh_sftpd:subsystem_spec([{vsn, 3}])
>> 					       ]}]).
>>
>> whereas the ssh_scpd module is base on the ssh_sftpd module from otp,
>> i.e.
>>
>> -module(ssh_scpd).
>> %-behaviour(ssh_daemon_channel).
>> -behaviour(ssh_channel).
>>
>> -define(UINT32(X), X:32/unsigned-big-integer).
>>
>> %% External exports
>> -export([subsystem_spec/1]).
>>
>> %% Callbacks
>> -export([init/1, handle_ssh_msg/2, handle_msg/2, terminate/2,
>> code_change/3]).
>>
>> implementing the callbacks similar to what we have in ssh_sftpd...
>>
>> now, when I start
>>
>> $ scp -P 45678 README ssh@REDACTED:README
>>
>> authentification works fine as implemented in auth/2, but somehow
>> the ssh channel behaviour is not used at all.
>>
>> ssh@REDACTED's password:
>> {error,{1,erl_parse,["syntax error before: ",[]]}}
>> $ Received disconnect from 127.0.0.1: 11: Application shutdown
>>
>> It seems like scp commands are send into the standard erlang shell
>> (which
>> I did not specify) and not into the channel.
>>
>> I am using R15B2.
>>
>> Could please someone help out here and give me some hint where to
>> proceed reading?
>>
>> Also an abstract description of the difference between the purposes of
>> ssh_cli and subsystems options would be appriciated.
>
> ssh_cli is to customize the shell I do not think you want to use
> ssh_cli at all. You should write your scp-deamon as subsystem and then
> use an existing scp client to connect to it or
> write your own erlang client that opens an ssh connection, requests
> the ssh-scp subsystem and then sends scp commands on the channel along
> the lines;
>
> ssh:connect ...
> ssh_connection:session_channel...
> ssh_connection:subsystem...
> ssh_connection:send...
>
> The client can use the ssh_channel behavior.

Thank you very much for your email.

True, I just want to implement my own scp-daemon.  For the client I'll
use standard system clients.

As shown in my email I was not yet successful to setup my own scp-daemon.
I wanted to use the

ssh:daemon(..., ..., [{subsystems, []}, ...])

subsystem option.  Is this the correct strategy?

As stated in my email the authentifaction works, but my ssh_scpd module
does not ever be run..., but the erlang shell instead...

My ssh_scpd module is based on the ssh_sftp module within otp,
but it seems not to be correct...

Any more help from is very much appreciated.

Thank you in advance,
  Stefan.




More information about the erlang-questions mailing list