<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">

<erlref>
  <header>
    <copyright>
      <year>2004</year><year>2015</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at
 
          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.

    </legalnotice>
    
    <title>ssh</title>
    <prepared></prepared>
    <docno></docno>
    <date>2007-10-06</date>
    <rev></rev>
  </header>
  <module>ssh</module>
  <modulesummary>Main API of the ssh application</modulesummary>
  <description>
    <p>Interface module for the <c>ssh</c> application.</p>
    <p>See <seealso marker="ssh:SSH_app#supported">ssh(6)</seealso> for details of supported version,
    algorithms and unicode support.</p>
  </description>

  <section>
    <title>OPTIONS</title>
    <p>The exact behaviour of some functions can be adjusted with the use of options which are documented together
    with the functions. Generally could each option be used at most one time in each function call. If given two or more
    times, the effect is not predictable unless explicitly documented.</p>
    <p>The options are of different kinds:</p>
    <taglist>
      <tag>Limits</tag>
      <item><p>which alters limits in the system, for example number of simultaneous login attempts.</p></item>

      <tag>Timeouts</tag>
      <item><p>which give some defined behaviour if too long time elapses before a given event or action,
      for example time to wait for an answer.</p></item>

      <tag>Callbacks</tag>
      <item><p>which gives the caller of the function the possibility to execute own code on some events,
      for example calling an own logging function or to perform an own login function</p></item>

      <tag>Behaviour</tag>
      <item><p>which changes the systems behaviour.</p></item>
    </taglist>
  </section>

  <section>
    <title>DATA TYPES</title>
    <p>Type definitions that are used more than once in
    this module, or abstractions to indicate the intended use of the data
    type, or both:</p>
    <taglist>
      <tag><c>boolean() =</c></tag>
      <item><p><c>true | false</c></p></item>
      <tag><c>string() =</c></tag>
      <item><p><c>[byte()]</c></p></item>
      <tag><c>ssh_daemon_ref() =</c></tag>
      <item><p>opaque() -
      as returned by <c>ssh:daemon/[1,2,3]</c></p></item>
      <tag><c>ssh_connection_ref() =</c></tag>
      <item><p>opaque() - as returned by <c>ssh:connect/3</c></p></item>
      <tag><c>ip_address() =</c></tag>
      <item><p><c>inet::ip_address</c></p></item>
      <tag><c>subsystem_spec() =</c></tag>
      <item><p><c>{subsystem_name(),
      {channel_callback(), channel_init_args()}}</c></p></item>
      <tag><c>subsystem_name() =</c></tag>
      <item><p><c>string()</c></p></item>
      <tag><c>channel_callback() =</c></tag>
      <item><p><c>atom()</c> - Name of the Erlang module
      implementing the subsystem using the <c>ssh_channel</c> behavior, see
      <seealso marker="ssh_channel">ssh_channel(3)</seealso></p></item>
      <tag><c>key_cb() =</c></tag>
      <item>
        <p><c>atom() | {atom(), list()}</c></p>
        <p><c>atom()</c> - Name of the erlang module implementing the behaviours
        <seealso marker="ssh_client_key_api">ssh_client_key_api</seealso> or
        <seealso marker="ssh_client_key_api">ssh_client_key_api</seealso> as the
        case maybe.</p>
        <p><c>list()</c> - List of options that can be passed to the callback module.</p>
      </item>
      <tag><c>channel_init_args() =</c></tag>
      <item><p><c>list()</c></p></item>

      <tag><c>algs_list() =</c></tag>
      <item><p><c>list( alg_entry() )</c></p></item>

      <tag><c>alg_entry() =</c></tag>
      <item><p><c>{kex, simple_algs()} | {public_key, simple_algs()} | {cipher, double_algs()} | {mac, double_algs()} | {compression, double_algs()}</c></p></item>

      <tag><c>simple_algs() =</c></tag>
      <item><p><c>list( atom() )</c></p></item>
      
      <tag><c>double_algs() =</c></tag>
      <item><p><c>[{client2serverlist,simple_algs()},{server2client,simple_algs()}] | simple_algs()</c></p></item>
     </taglist>
</section>

 <funcs>
   
   <func>
     <name>close(ConnectionRef) -> ok </name>
      <fsummary>Closes an SSH connection.</fsummary>
      <type>
	<v>ConnectionRef = ssh_connection_ref()</v>
      </type>
      <desc><p>Closes an SSH connection.</p>
      </desc>
    </func>
    
    <func>
      <name>connect(Host, Port, Options) -> </name>
      <name>connect(Host, Port, Options, Timeout) -> {ok,
      ssh_connection_ref()} | {error, Reason}</name>
      <fsummary>Connects to an SSH server.</fsummary>
      <type>
        <v>Host = string()</v>
	<v>Port = integer()</v>
	<d><c><![CDATA[22]]></c> is default, the assigned well-known port
	number for SSH.</d>
	<v>Options = [{Option, Value}]</v>
	<v>Timeout = infinity | integer()</v>
	<d>Negotiation time-out in milli-seconds. The default value is <c>infinity</c>.
	For connection time-out, use option <c>{connect_timeout, timeout()}</c>.</d>
      </type>
      <desc>
	<p>Connects to an SSH server. No channel is started. This is done
	by calling
	<seealso marker="ssh_connection#session_channel/2">
	ssh_connection:session_channel/[2, 4]</seealso>.</p>
	<p>Options:</p>
	<taglist>
	  <tag><c><![CDATA[{inet, inet | inet6}]]></c></tag>
	  <item>
	  <p>IP version to use.</p>
	  </item>
          <tag><c><![CDATA[{user_dir, string()}]]></c></tag>
	  <item>
	    <p>Sets the user directory, that is, the directory containing
	    <c>ssh</c> configuration files for the user, such as
	    <c><![CDATA[known_hosts]]></c>, <c><![CDATA[id_rsa,
	    id_dsa]]></c>, and
	    <c><![CDATA[authorized_key]]></c>. Defaults to the
	    directory normally referred to as
	    <c><![CDATA[~/.ssh]]></c>.</p>
	  </item>
	  <tag><c><![CDATA[{dsa_pass_phrase, string()}]]></c></tag>
	  <item>
	    <p>If the user DSA key is protected by a passphrase, it can be
	    supplied with this option.
	    </p>
	  </item>
	  <tag><c><![CDATA[{rsa_pass_phrase, string()}]]></c></tag>
	  <item>
	    <p>If the user RSA key is protected by a passphrase, it can be
	    supplied with this option.
	    </p>
	  </item>
          <tag><c><![CDATA[{silently_accept_hosts, boolean()}]]></c></tag>
	  <item>
	    <p>When <c>true</c>, hosts are added to the
	    file <c><![CDATA[known_hosts]]></c> without asking the user.
	    Defaults to <c>false</c>.
	    </p>
	  </item>
	  <tag><c><![CDATA[{user_interaction, boolean()}]]></c></tag>
	  <item>
	    <p>If <c>false</c>, disables the client to connect to the server
	    if any user interaction is needed, such as accepting
	    the server to be added to the <c>known_hosts</c> file, or
	    supplying a password. Defaults to <c>true</c>.
	    Even if user interaction is allowed it can be
	    suppressed by other options, such as <c>silently_accept_hosts</c>
	    and <c>password</c>. However, those optins are not always desirable
	    to use from a security point of view.</p>
	  </item>

	  <tag><c><![CDATA[{disconnectfun, fun(Reason:term()) -> _}]]></c></tag>
	  <item>
	    <p>Provides a fun to implement your own logging when a server disconnects the client.</p>
	  </item>

	  <tag><c><![CDATA[{unexpectedfun, fun(Message:term(), Peer) -> report | skip }]]></c></tag>
	  <item>
	    <p>Provides a fun to implement your own logging or other action when an unexpected message arrives.
	    If the fun returns <c>report</c> the usual info report is issued but if <c>skip</c> is returned no
	    report is generated.</p>
	    <p><c>Peer</c> is in the format of <c>{Host,Port}</c>.</p>
	  </item>

	  <tag><c><![CDATA[{public_key_alg, 'ssh-rsa' | 'ssh-dss'}]]></c></tag>
	  <item>
	    <note>
	      <p>This option will be removed in OTP 20, but is kept for compatibility. It is ignored if
	      the preferred <c>pref_public_key_algs</c> option is used.</p>
	    </note>
            <p>Sets the preferred public key algorithm to use for user
	    authentication. If the preferred algorithm fails,
	    the other algorithm is tried. If <c>{public_key_alg, 'ssh-rsa'}</c> is set, it is translated
	    to <c>{pref_public_key_algs, ['ssh-rsa','ssh-dss']}</c>.  If it is 
	    <c>{public_key_alg, 'ssh-dss'}</c>, it is translated
	    to <c>{pref_public_key_algs, ['ssh-dss','ssh-rsa']}</c>.
	    </p>
	  </item>

	  <tag><c><![CDATA[{pref_public_key_algs, list()}]]></c></tag>
	  <item>
            <p>List of user (client) public key algorithms to try to use.</p>
	    <p>The default value is 
	    <c><![CDATA[['ssh-rsa','ssh-dss','ecdsa-sha2-nistp256','ecdsa-sha2-nistp384','ecdsa-sha2-nistp521'] ]]></c>
	    </p>
	    <p>If there is no public key of a specified type available, the corresponding entry is ignored.</p>
	  </item>

	  <tag><c><![CDATA[{preferred_algorithms, algs_list()}]]></c></tag>
	  <item>
            <p>List of algorithms to use in the algorithm negotiation. The default <c>algs_list()</c> can
	    be obtained from <seealso marker="#default_algorithms/0">default_algorithms/0</seealso>.
	    </p>
	    <p>If an alg_entry() is missing in the algs_list(), the default value is used for that entry.</p>
	    <p>Here is an example of this option:</p>
	<code>
{preferred_algorithms, 
 [{public_key,['ssh-rsa','ssh-dss']},
  {cipher,[{client2server,['aes128-ctr']},
           {server2client,['aes128-cbc','3des-cbc']}]},
  {mac,['hmac-sha2-256','hmac-sha1']},
  {compression,[none,zlib]}
}
</code>
        <p>The example specifies different algorithms in the two directions (client2server and server2client),
	for cipher but specifies the same algorithms for mac and compression in both directions.
	The kex (key exchange) is implicit but public_key is set explicitly.</p>

        <warning>
	  <p>Changing the values can make a connection less secure. Do not change unless you
	  know exactly what you are doing. If you do not understand the values then you
	  are not supposed to change them.</p>
	</warning>
	  </item>

	  <tag><c><![CDATA[{dh_gex_limits,{Min=integer(),I=integer(),Max=integer()}}]]></c></tag>
	  <item>
	    <p>Sets the three diffie-hellman-group-exchange parameters that guides the connected server in choosing a group.
	    See RFC 4419 for the function of thoose.  The default value is <c>{1024, 6144, 8192}</c>.
	    </p>
	  </item>

	  <tag><c><![CDATA[{connect_timeout, timeout()}]]></c></tag>
	  <item>
	    <p>Sets a time-out on the transport layer
	    connection. For <c>gen_tcp</c> the time is in milli-seconds and the default value is
	    <c>infinity</c>.</p>
	  </item>
	  <tag><c><![CDATA[{user, string()}]]></c></tag>
          <item>
	    <p>Provides a username. If this option is not given, <c>ssh</c>
	    reads from the environment (<c><![CDATA[LOGNAME]]></c> or
	    <c><![CDATA[USER]]></c> on UNIX,
	    <c><![CDATA[USERNAME]]></c> on Windows).</p>
          </item>
	  <tag><c><![CDATA[{password, string()}]]></c></tag>
          <item>
	    <p>Provides a password for password authentication.
	    If this option is not given, the user is asked for a
	    password, if the password authentication method is
	    attempted.</p>
          </item>
	  <tag><c><![CDATA[{key_cb, key_cb()}]]></c></tag>
	  <item>
	    <p>Module implementing the behaviour <seealso
	    marker="ssh_client_key_api">ssh_client_key_api</seealso>. Can be used to
	    customize the handling of public keys. If callback options are provided
	    along with the module name, they are made available to the callback
	    module via the options passed to it under the key 'key_cb_private'.
	    </p>
	  </item>
	  <tag><c><![CDATA[{quiet_mode, atom() = boolean()}]]></c></tag>
	  <item>
	    <p>If <c>true</c>, the client does not print anything on authorization.</p>
	  </item>

	  <tag><c><![CDATA[{id_string, random | string()}]]></c></tag>
	  <item>
	    <p>The string that the client presents to a connected server initially.  The default value is "Erlang/VSN" where VSN is the ssh application version number.
	    </p>
	    <p>The value <c>random</c> will cause a random string to be created at each connection attempt.  This is to make it a bit more difficult for a malicious peer to find the ssh software brand and version.
	    </p>
	  </item>

	  <tag><c><![CDATA[{fd, file_descriptor()}]]></c></tag>
	  <item>
	    <p>Allows an existing file descriptor to be used
	  (by passing it on to the transport protocol).</p></item>
	  <tag><c><![CDATA[{rekey_limit, integer()}]]></c></tag>
	  <item>
	    <p>Provides, in bytes, when rekeying is to be initiated.
	    Defaults to once per each GB and once per hour.</p>
	  </item>
	  <tag><c><![CDATA[{idle_time, integer()}]]></c></tag>
	  <item>
	  <p>Sets a time-out on a connection when no channels are active.
	  Defaults to <c>infinity</c>.</p></item>
	  <tag><c><![CDATA[{ssh_msg_debug_fun, fun(ConnectionRef::ssh_connection_ref(), AlwaysDisplay::boolean(), Msg::binary(), LanguageTag::binary()) -> _}]]></c></tag>
	  <item>
	    <p>Provide a fun to implement your own logging of the SSH message SSH_MSG_DEBUG. The last three parameters are from the message, see RFC4253, section 11.3. The <c>ConnectionRef</c> is the reference to the connection on which the message arrived. The return value from the fun is not checked.</p>
	    <p>The default behaviour is ignore the message.
	    To get a printout for each message with <c>AlwaysDisplay = true</c>, use for example <c>{ssh_msg_debug_fun, fun(_,true,M,_)-> io:format("DEBUG: ~p~n", [M]) end}</c></p>
	  </item>

	</taglist>
      </desc>   
    </func>

    <func>
      <name>connection_info(ConnectionRef, [Option]) ->[{Option,
      Value}]</name>
      <fsummary>Retrieves information about a connection.</fsummary>
      <type>
        <v>Option = client_version | server_version | user | peer | sockname </v>
	<v>Value = [option_value()] </v>
	<v>option_value() = {{Major::integer(), Minor::integer()}, VersionString::string()} |
	User::string() |  Peer::{inet:hostname(), {inet::ip_adress(), inet::port_number()}} |
	Sockname::{inet::ip_adress(), inet::port_number()}</v>
      </type>
      <desc>
        <p>Retrieves information about a connection.</p>
      </desc>
    </func>
    
    <func>
      <name>daemon(Port) -> </name>
      <name>daemon(Port, Options) -> </name>
      <name>daemon(HostAddress, Port, Options) -> {ok,
      ssh_daemon_ref()} | {error, atom()}</name>
      <fsummary>Starts a server listening for SSH connections 
      on the given port.</fsummary>
      <type>
        <v>Port = integer()</v>
	<v>HostAddress = ip_address() | any</v>
	<v>Options = [{Option, Value}]</v>
        <v>Option = atom()</v>
	<v>Value = term()</v>
      </type>
      <desc>
        <p>Starts a server listening for SSH connections on the given
        port.</p>
	<p>Options:</p>
        <taglist>
	  <tag><c><![CDATA[{inet, inet | inet6}]]></c></tag>
	  <item><p>IP version to use when the host address is specified as <c>any</c>.</p></item>
	  <tag><c><![CDATA[{subsystems, [subsystem_spec()]}]]></c></tag>
	  <item>
	    <p>Provides specifications for handling of subsystems. The
	    "sftp" subsystem specification is retrieved by calling
	    <c>ssh_sftpd:subsystem_spec/1</c>. If the subsystems option is
	    not present, the value of
	    <c>[ssh_sftpd:subsystem_spec([])]</c> is used.
	    The option can be set to the empty list if
	    you do not want the daemon to run any subsystems.</p>
	  </item>
	  <tag><c><![CDATA[{shell, {Module, Function, Args} |
	  fun(string() = User) - > pid() | fun(string() = User,
	  ip_address() = PeerAddr) -> pid()}]]></c></tag>
	  <item>
	    <p>Defines the read-eval-print loop used when a shell is
	    requested by the client. The default is to use the Erlang shell:
	    <c><![CDATA[{shell, start, []}]]></c></p>
	  </item>
	  <tag><c><![CDATA[{ssh_cli, {channel_callback(),
	  channel_init_args()} | no_cli}]]></c></tag>
	  <item>
	    <p>Provides your own CLI implementation, that is, a channel callback
	    module that implements a shell and command execution. The shell
	    read-eval-print loop can be customized, using the
	    option <c>shell</c>. This means less work than implementing
	    an own CLI channel. If set to <c>no_cli</c>, the CLI channels
	    are disabled and only subsystem channels are allowed.</p>
	  </item>
	  <tag><c><![CDATA[{user_dir, string()}]]></c></tag>
	  <item>
	    <p>Sets the user directory. That is, the directory containing
	    <c>ssh</c> configuration files for the user, such as
	    <c><![CDATA[known_hosts]]></c>, <c><![CDATA[id_rsa,
	    id_dsa]]></c>, and
	    <c><![CDATA[authorized_key]]></c>. Defaults to the
	    directory normally referred to as
	    <c><![CDATA[~/.ssh]]></c>.</p>
	  </item>
          <tag><c><![CDATA[{system_dir, string()}]]></c></tag>
          <item>
            <p>Sets the system directory, containing the host key files
            that identify the host keys for <c>ssh</c>. Defaults to
            <c><![CDATA[/etc/ssh]]></c>. For security reasons,
            this directory is normally accessible only to the root user.</p>
	  </item>

	  <tag><c><![CDATA[{auth_methods, string()}]]></c></tag>
	  <item>
	    <p>Comma-separated string that determines which
	    authentication methods that the server is to support and
	    in what order they are tried. Defaults to
	    <c><![CDATA["publickey,keyboard-interactive,password"]]></c></p>
          </item>

	  <tag><c><![CDATA[{auth_method_kb_interactive_data, PromptTexts}]]></c>
	  <br/><c>where:</c>
	  <br/><c>PromptTexts = kb_int_tuple()  | fun(Peer::{IP::tuple(),Port::integer()}, User::string(), Service::string()) ->  kb_int_tuple()</c>
	  <br/><c>kb_int_tuple() = {Name::string(), Instruction::string(), Prompt::string(), Echo::boolean()}</c>
	  </tag>
	  <item>
	    <p>Sets the text strings that the daemon sends to the client for presentation to the user when using <c>keyboar-interactive</c> authentication. If the fun/3 is used, it is called when the actual authentication occurs and may therefore return dynamic data like time, remote ip etc.</p>
	    <p>The parameter <c>Echo</c> guides the client about need to hide the password.</p>
	    <p>The default value is:
	    <c>{auth_method_kb_interactive_data, {"SSH server", "Enter password for \""++User++"\"", "password: ", false}></c></p>
          </item>

	  <tag><c><![CDATA[{user_passwords, [{string() = User,
	  string() = Password}]}]]></c></tag>
	  <item>
            <p>Provides passwords for password authentication. The passwords
	    are used when someone tries to connect to the server and
	    public key user-authentication fails. The option provides
	    a list of valid usernames and the corresponding passwords.
	    </p>
          </item>
          <tag><c><![CDATA[{password, string()}]]></c></tag>
          <item>
            <p>Provides a global password that authenticates any
              user. From a security perspective this option makes
	      the server very vulnerable.</p>
	  </item>

	  <tag><c><![CDATA[{preferred_algorithms, algs_list()}]]></c></tag>
	  <item>
            <p>List of algorithms to use in the algorithm negotiation. The default <c>algs_list()</c> can
	    be obtained from <seealso marker="#default_algorithms/0">default_algorithms/0</seealso>.
	    </p>
	    <p>If an alg_entry() is missing in the algs_list(), the default value is used for that entry.</p>
	    <p>Here is an example of this option:</p>
	<code>
{preferred_algorithms, 
 [{public_key,['ssh-rsa','ssh-dss']},
  {cipher,[{client2server,['aes128-ctr']},
           {server2client,['aes128-cbc','3des-cbc']}]},
  {mac,['hmac-sha2-256','hmac-sha1']},
  {compression,[none,zlib]}
}
</code>
        <p>The example specifies different algorithms in the two directions (client2server and server2client),
	for cipher but specifies the same algorithms for mac and compression in both directions.
	The kex (key exchange) is implicit but public_key is set explicitly.</p>

        <warning>
	  <p>Changing the values can make a connection less secure. Do not change unless you
	  know exactly what you are doing. If you do not understand the values then you
	  are not supposed to change them.</p>
	</warning>
	  </item>

	  <tag><c><![CDATA[{dh_gex_groups, [{Size=integer(),G=integer(),P=integer()}] | {file,filename()} {ssh_moduli_file,filename()} }]]></c></tag>
	  <item>
	    <p>Defines the groups the server may choose among when diffie-hellman-group-exchange is negotiated.
	    See RFC 4419 for details. The three variants of this option are:
	    </p>
	    <taglist>
	      <tag><c>{Size=integer(),G=integer(),P=integer()}</c></tag>
	      <item>The groups are given explicitly in this list. There may be several elements with the same <c>Size</c>.
	      In such a case, the server will choose one randomly in the negotiated Size.
	      </item>
	      <tag><c>{file,filename()}</c></tag>
	      <item>The file must have one or more three-tuples <c>{Size=integer(),G=integer(),P=integer()}</c> 
	      terminated by a dot. The file is read when the daemon starts.
	      </item>
	      <tag><c>{ssh_moduli_file,filename()}</c></tag>
	      <item>The file must be in
	      <seealso marker="public_key:public_key#dh_gex_group/4">ssh-keygen moduli file format</seealso>.
	      The file is read when the daemon starts.
	      </item>
	    </taglist>
	    <p>The default list is fetched from the 
	      <seealso marker="public_key:public_key#dh_gex_group/4">public_key</seealso> application.
	    </p>
	  </item>

	  <tag><c><![CDATA[{dh_gex_limits,{Min=integer(),Max=integer()}}]]></c></tag>
	  <item>
	    <p>Limits what a client can ask for in diffie-hellman-group-exchange.
	    The limits will be
	    <c>{MaxUsed = min(MaxClient,Max), MinUsed = max(MinClient,Min)}</c> where <c>MaxClient</c> and 
	    <c>MinClient</c> are the values proposed by a connecting client.
	    </p>
	    <p>The default value is <c>{0,infinity}</c>.
	    </p>
	    <p>If <c>MaxUsed &lt; MinUsed</c> in a key exchange, it will fail with a disconnect.
	    </p>
	    <p>See RFC 4419 for the function of the Max and Min values.</p>
	  </item>

	  <tag><c><![CDATA[{pwdfun, fun(User::string(), Password::string(), PeerAddress::{ip_adress(),port_number()}, State::any()) -> boolean() | disconnect | {boolean(),any()} }]]></c></tag>
	  <item>
	    <p>Provides a function for password validation. This could used for calling an external system or if
	    passwords should be stored as a hash. The fun returns:
	    </p>
	    <list type="bulleted">
	      <item><c>true</c> if the user and password is valid and</item>
	      <item><c>false</c> otherwise.</item> 
	    </list>
	    <p>This fun can also be used to make delays in authentication tries for example by calling
	      <seealso marker="stdlib:timer#sleep/1">timer:sleep/1</seealso>. To facilitate counting of failed tries
	      the <c>State</c> variable could be used. This state is per connection only. The first time the pwdfun
	      is called for a connection, the <c>State</c> variable has the value <c>undefined</c>.  
	      The pwdfun can return - in addition to the values above - a new state
	      as:
	    </p>
	    <list type="bulleted">
	      <item><c>{true,  NewState:any()}</c> if the user and password is valid or</item>
	      <item><c>{false, NewState:any()}</c> if the user or password is invalid</item> 
	    </list>
	    <p>A third usage is to block login attempts from a missbehaving peer. The <c>State</c> described above 
	    can be used for this. In addition to the responses above, the following return value is introduced:
	    </p>
	    <list type="bulleted">
	      <item><c>disconnect</c> if the connection should be closed immediately after sending a SSH_MSG_DISCONNECT
	      message.</item>
	    </list>
	  </item>

	  <tag><c><![CDATA[{pwdfun, fun(User::string(), Password::string()) -> boolean()}]]></c></tag>
	  <item>
	    <p>Provides a function for password validation. This function is called
	      with user and password as strings, and returns
	      <c><![CDATA[true]]></c> if the password is valid and
	      <c><![CDATA[false]]></c> otherwise.</p>
	      <p>This option (<c>{pwdfun,fun/2}</c>) is the same as a subset of the previous 
	      (<c>{pwdfun,fun/4}</c>). It is kept for compatibility.</p>
	  </item>

	  <tag><c><![CDATA[{negotiation_timeout, integer()}]]></c></tag>
	  <item>
	    <p>Maximum time in milliseconds for the authentication negotiation.
	    Defaults to 120000 (2 minutes). If the client fails to log in within this time,
	    the connection is closed.
	    </p>
	  </item>

	  <tag><c><![CDATA[{max_sessions, pos_integer()}]]></c></tag>
	  <item>
	    <p>The maximum number of simultaneous sessions that are accepted at any time
	    for this daemon. This includes sessions that are being authorized.
	    Thus, if set to <c>N</c>, and <c>N</c> clients have connected but not started
	    the login process, connection attempt <c>N+1</c> is aborted.
	    If <c>N</c> connections are authenticated and still logged in, no more logins
	    are accepted until one of the existing ones log out.
	    </p>
	    <p>The counter is per listening port. Thus, if two daemons are started, one with
	    <c>{max_sessions,N}</c> and the other with <c>{max_sessions,M}</c>, in total
	    <c>N+M</c> connections are accepted for the whole <c>ssh</c> application.
	    </p>
	    <p>Notice that if <c>parallel_login</c> is <c>false</c>, only one client
	    at a time can be in the authentication phase.
	    </p>
	    <p>By default, this option is not set. This means that the number is not limited.
	    </p>
	  </item>

	  <tag><c><![CDATA[{max_channels, pos_integer()}]]></c></tag>
	  <item>
	    <p>The maximum number of channels with active remote subsystem that are accepted for
	    each connection to this daemon</p>
	    <p>By default, this option is not set. This means that the number is not limited.
	    </p>
	  </item>


	  <tag><c><![CDATA[{parallel_login, boolean()}]]></c></tag>
	  <item>
	    <p>If set to false (the default value), only one login is handled at a time.
	    If set to true, an unlimited number of login attempts are allowed simultaneously.
	    </p>
	    <p>If the <c>max_sessions</c> option is set to <c>N</c> and <c>parallel_login</c>
	    is set to <c>true</c>, the maximum number of simultaneous login attempts at any time is
	    limited to <c>N-K</c>, where <c>K</c> is the number of authenticated connections present
	    at this daemon.
	    </p>
	    <warning>
	      <p>Do not enable <c>parallel_logins</c> without protecting the server by other means,
	      for example, by the <c>max_sessions</c> option or a firewall configuration. If set to
	      <c>true</c>, there is no protection against DOS attacks.</p>
	    </warning>
	  </item>

	  <tag><c><![CDATA[{minimal_remote_max_packet_size, non_negative_integer()}]]></c></tag>
	  <item>
	    <p>The least maximum packet size that the daemon will accept in channel open requests from the client.  The default value is 0.
	    </p>
	  </item>

	  <tag><c><![CDATA[{id_string, random | string()}]]></c></tag>
	  <item>
	    <p>The string the daemon will present to a connecting peer initially.  The default value is "Erlang/VSN" where VSN is the ssh application version number.
	    </p>
	    <p>The value <c>random</c> will cause a random string to be created at each connection attempt.  This is to make it a bit more difficult for a malicious peer to find the ssh software brand and version.
	    </p>
	  </item>

	  <tag><c><![CDATA[{key_cb, key_cb()}]]></c></tag>
	  <item>
	    <p>Module implementing the behaviour <seealso
	    marker="ssh_server_key_api">ssh_server_key_api</seealso>. Can be used to
	    customize the handling of public keys. If callback options are provided
	    along with the module name, they are made available to the callback
	    module via the options passed to it under the key 'key_cb_private'.
	    </p>
	  </item>
	  
	  <tag><c>{profile, atom()}</c></tag>
	  <item>
	    <p>Used together with <c>ip-address</c> and <c>port</c> to
	    uniquely identify a ssh daemon. This can be useful in a
	    virtualized environment, where there can be more that one
	    server that has the same <c>ip-address</c> and
	    <c>port</c>. If this property is not explicitly set, it is
	    assumed that the the <c>ip-address</c> and <c>port</c>
	    uniquely identifies the SSH daemon.
	    </p>
	  </item>
	  
	  <tag><c><![CDATA[{fd, file_descriptor()}]]></c></tag>
	  <item>
	    <p>Allows an existing file-descriptor to be used
	  (passed on to the transport protocol).</p></item>
	  <tag><c><![CDATA[{failfun, fun(User::string(),
	  PeerAddress::ip_address(), Reason::term()) -> _}]]></c></tag>
	  <item>
	    <p>Provides a fun to implement your own logging when a user fails to authenticate.</p>
	  </item>
	  <tag><c><![CDATA[{connectfun, fun(User::string(), PeerAddress::ip_address(),
	  Method::string()) ->_}]]></c></tag>
	  <item>
	    <p>Provides a fun to implement your own logging when a user authenticates to the server.</p>
	  </item>
	  <tag><c><![CDATA[{disconnectfun, fun(Reason:term()) -> _}]]></c></tag>
	  <item>
	    <p>Provides a fun to implement your own logging when a user disconnects from the server.</p>
	  </item>

	  <tag><c><![CDATA[{unexpectedfun, fun(Message:term(), Peer) -> report | skip }]]></c></tag>
	  <item>
	    <p>Provides a fun to implement your own logging or other action when an unexpected message arrives.
	    If the fun returns <c>report</c> the usual info report is issued but if <c>skip</c> is returned no
	    report is generated.</p>
	    <p><c>Peer</c> is in the format of <c>{Host,Port}</c>.</p>
	  </item>

	  <tag><c><![CDATA[{ssh_msg_debug_fun, fun(ConnectionRef::ssh_connection_ref(), AlwaysDisplay::boolean(), Msg::binary(), LanguageTag::binary()) -> _}]]></c></tag>
	  <item>
	    <p>Provide a fun to implement your own logging of the SSH message SSH_MSG_DEBUG. The last three parameters are from the message, see RFC4253, section 11.3. The <c>ConnectionRef</c> is the reference to the connection on which the message arrived. The return value from the fun is not checked.</p>
	    <p>The default behaviour is ignore the message.
	    To get a printout for each message with <c>AlwaysDisplay = true</c>, use for example <c>{ssh_msg_debug_fun, fun(_,true,M,_)-> io:format("DEBUG: ~p~n", [M]) end}</c></p>
	  </item>

	</taglist>
      </desc>   
    </func>

    <func>
      <name>default_algorithms() -> algs_list()</name>
      <fsummary>Get a list declaring the supported algorithms</fsummary>
      <desc>
	<p>Returns a key-value list, where the keys are the different types of algorithms and the values are the
	algorithms themselves. An example:</p>
	<code>
20> ssh:default_algorithms().
[{kex,['diffie-hellman-group1-sha1']},
 {public_key,['ssh-rsa','ssh-dss']},
 {cipher,[{client2server,['aes128-ctr','aes128-cbc','3des-cbc']},
          {server2client,['aes128-ctr','aes128-cbc','3des-cbc']}]},
 {mac,[{client2server,['hmac-sha2-256','hmac-sha1']},
       {server2client,['hmac-sha2-256','hmac-sha1']}]},
 {compression,[{client2server,[none,zlib]},
               {server2client,[none,zlib]}]}]
21> 
</code>
      </desc>
    </func>

    <func>
      <name>shell(Host) -> </name>
      <name>shell(Host, Option) -> </name>
      <name>shell(Host, Port, Option) -> _</name>
      <fsummary>Starts an interactive shell over an SSH server.</fsummary>
      <type>
        <v>Host = string()</v>
	<v>Port = integer()</v>
	<v>Options - see ssh:connect/3</v>
      </type>
      <desc>
        <p>Starts an interactive shell over an SSH server on the
	given <c>Host</c>. The function waits for user input,
	and does not return until the remote shell is ended (that is,
	exit from the shell).
	</p>
      </desc>
    </func>

    <func>
      <name>start() -> </name>
      <name>start(Type) -> ok | {error, Reason}</name>
      <fsummary>Starts the SSH application.</fsummary>
      <type>
        <v>Type =  permanent | transient | temporary</v>
	<v>Reason = term() </v>
      </type>
      <desc>
        <p>Utility function that starts the applications <c>crypto</c>, <c>public_key</c>,
	and <c>ssh</c>. Default type is <c>temporary</c>.
	For more information, see the <seealso marker="kernel:application">application(3)</seealso>
	manual page in <c>kernel</c>.</p>
      </desc>
    </func>

    <func>
      <name>stop() -> ok | {error, Reason}</name>
      <fsummary>Stops the <c>ssh</c> application.</fsummary>
      <type>
        <v>Reason = term()</v>
      </type>
      <desc>
        <p>Stops the <c>ssh</c> application.
	For more information, see the <seealso marker="kernel:application">application(3)</seealso>
	manual page in <c>kernel</c>.</p>
      </desc>
    </func>
    
    <func>
      <name>stop_daemon(DaemonRef) -> </name>
      <name>stop_daemon(Address, Port) -> ok </name>
      <fsummary>Stops the listener and all connections started by 
      the listener.</fsummary>
      <type>
	<v>DaemonRef = ssh_daemon_ref()</v>
	<v>Address = ip_address()</v>
	<v>Port = integer()</v>
      </type>
      <desc>
	<p>Stops the listener and all connections started by 
	the listener.</p>
      </desc>
    </func>

    <func>
      <name>stop_listener(DaemonRef) -> </name>
      <name>stop_listener(Address, Port) -> ok </name>
      <fsummary>Stops the listener, but leaves existing connections started
	by the listener operational.</fsummary>
      <type>
	<v>DaemonRef = ssh_daemon_ref()</v>
        <v>Address = ip_address()</v>
	<v>Port = integer()</v>
      </type>
      <desc>
	<p>Stops the listener, but leaves existing connections started
	by the listener operational.</p>
      </desc>
    </func>

  </funcs>
  
</erlref>
