20042014 Ericsson AB. All Rights Reserved. The contents of this file are subject to the Erlang Public License, Version 1.1, (the "License"); you may not use this file except in compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. ssh 2007-10-06
ssh Main API of the ssh application

Interface module for the ssh application.

SSH For application dependencies see ssh(6) Supported SSH version is 2.0. Supported MAC algorithms: hmac-sha2-256 and hmac-sha1. Supported encryption algorithms: aes128-ctr, aes128-cb and 3des-cbc. Supported key exchange algorithms: diffie-hellman-group1-sha1. Supports unicode filenames if the emulator and the underlaying OS support it. See section DESCRIPTION in the file manual page in kernel for information about this subject. Supports unicode in shell and CLI.
DATA TYPES

Type definitions that are used more than once in this module, or abstractions to indicate the intended use of the data type, or both:

boolean()

= true | false

string()

= [byte()]

ssh_daemon_ref()

Opaque to the user, returned by ssh:daemon/[1,2,3]

ssh_connection_ref()

Opaque to the user, returned by ssh:connect/3

ip_address()

inet::ip_address

subsystem_spec()

= {subsystem_name(), {channel_callback(), channel_init_args()}}

subsystem_name()

= string()

channel_callback()

= atom() - Name of the Erlang module implementing the subsystem using the ssh_channel behavior, see ssh_channel(3)

channel_init_args()

= list()

close(ConnectionRef) -> ok Closes an SSH connection. ConnectionRef = ssh_connection_ref()

Closes an SSH connection.

connect(Host, Port, Options) -> connect(Host, Port, Options, Timeout) -> {ok, ssh_connection_ref()} | {error, Reason} Connects to an SSH server. Host = string() Port = integer() is default, the assigned well-known port number for SSH. Options = [{Option, Value}] Timeout = infinity | integer() Negotiation time-out in milli-seconds. The default value is infinity. For connection time-out, use option {connect_timeout, timeout()}.

Connects to an SSH server. No channel is started. This is done by calling ssh_connection:session_channel/[2, 4].

Options:

IP version to use.

Sets the user directory, that is, the directory containing ssh configuration files for the user, such as , , and . Defaults to the directory normally referred to as .

If the user DSA key is protected by a passphrase, it can be supplied with this option.

If the user RSA key is protected by a passphrase, it can be supplied with this option.

When true, hosts are added to the file without asking the user. Defaults to false.

If false, disables the client to connect to the server if any user interaction is needed, such as accepting the server to be added to the known_hosts file, or supplying a password. Defaults to true. Even if user interaction is allowed it can be suppressed by other options, such as silently_accept_hosts and password. However, those optins are not always desirable to use from a security point of view.

Sets the preferred public key algorithm to use for user authentication. If the preferred algorithm fails, the other algorithm is tried. The default is to try first.

List of public key algorithms to try to use. 'ssh-rsa' and 'ssh-dss' are available. Overrides

Sets a time-out on the transport layer connection. For gen_tcp the time is in milli-seconds and the default value is infinity.

Provides a username. If this option is not given, ssh reads from the environment ( or on UNIX, on Windows).

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.

Module implementing the behaviour ssh_client_key_api. Can be used to customize the handling of public keys.

If true, the client does not print anything on authorization.

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.

The value random 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.

Allows an existing file descriptor to be used (by passing it on to the transport protocol).

Provides, in bytes, when rekeying is to be initiated. Defaults to once per each GB and once per hour.

Sets a time-out on a connection when no channels are active. Defaults to infinity.

_}]]>

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 ConnectionRef is the reference to the connection on which the message arrived. The return value from the fun is not checked.

The default behaviour is ignore the message. To get a printout for each message with AlwaysDisplay = true, use for example {ssh_msg_debug_fun, fun(_,true,M,_)-> io:format("DEBUG: ~p~n", [M]) end}

connection_info(ConnectionRef, [Option]) ->[{Option, Value}] Retrieves information about a connection. Option = client_version | server_version | user | peer | sockname Value = [option_value()] 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()}

Retrieves information about a connection.

daemon(Port) -> daemon(Port, Options) -> daemon(HostAddress, Port, Options) -> {ok, ssh_daemon_ref()} | {error, atom()} Starts a server listening for SSH connections on the given port. Port = integer() HostAddress = ip_address() | any Options = [{Option, Value}] Option = atom() Value = term()

Starts a server listening for SSH connections on the given port.

Options:

IP version to use when the host address is specified as any.

Provides specifications for handling of subsystems. The "sftp" subsystem specification is retrieved by calling ssh_sftpd:subsystem_spec/1. If the subsystems option is not present, the value of [ssh_sftpd:subsystem_spec([])] is used. The option can be set to the empty list if you do not want the daemon to run any subsystems.

pid() | fun(string() = User, ip_address() = PeerAddr) -> pid()}]]>

Defines the read-eval-print loop used when a shell is requested by the client. The default is to use the Erlang shell:

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 shell. This means less work than implementing an own CLI channel. If set to no_cli, the CLI channels are disabled and only subsystem channels are allowed.

Sets the user directory. That is, the directory containing ssh configuration files for the user, such as , , and . Defaults to the directory normally referred to as .

Sets the system directory, containing the host key files that identify the host keys for ssh. Defaults to . For security reasons, this directory is normally accessible only to the root user.

Comma-separated string that determines which authentication methods that the server is to support and in what order they are tried. Defaults to

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.

Provides a global password that authenticates any user. From a security perspective this option makes the server very vulnerable.

boolean()}]]>

Provides a function for password validation. This function is called with user and password as strings, and returns if the password is valid and otherwise.

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.

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 N, and N clients have connected but not started the login process, connection attempt N+1 is aborted. If N connections are authenticated and still logged in, no more logins are accepted until one of the existing ones log out.

The counter is per listening port. Thus, if two daemons are started, one with {max_sessions,N} and the other with {max_sessions,M}, in total N+M connections are accepted for the whole ssh application.

Notice that if parallel_login is false, only one client at a time can be in the authentication phase.

By default, this option is not set. This means that the number is not limited.

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.

If the max_sessions option is set to N and parallel_login is set to true, the maximum number of simultaneous login attempts at any time is limited to N-K, where K is the number of authenticated connections present at this daemon.

Do not enable parallel_logins without protecting the server by other means, for example, by the max_sessions option or a firewall configuration. If set to true, there is no protection against DOS attacks.

The least maximum packet size that the daemon will accept in channel open requests from the client. The default value is 0.

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.

The value random 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.

Module implementing the behaviour ssh_server_key_api. Can be used to customize the handling of public keys.

Allows an existing file-descriptor to be used (passed on to the transport protocol).

_}]]>

Provides a fun to implement your own logging when a user fails to authenticate.

_}]]>

Provides a fun to implement your own logging when a user authenticates to the server.

_}]]>

Provides a fun to implement your own logging when a user disconnects from the server.

_}]]>

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 ConnectionRef is the reference to the connection on which the message arrived. The return value from the fun is not checked.

The default behaviour is ignore the message. To get a printout for each message with AlwaysDisplay = true, use for example {ssh_msg_debug_fun, fun(_,true,M,_)-> io:format("DEBUG: ~p~n", [M]) end}

shell(Host) -> shell(Host, Option) -> shell(Host, Port, Option) -> _ Starts an interactive shell over an SSH server. Host = string() Port = integer() Options - see ssh:connect/3

Starts an interactive shell over an SSH server on the given Host. The function waits for user input, and does not return until the remote shell is ended (that is, exit from the shell).

start() -> start(Type) -> ok | {error, Reason} Starts the SSH application. Type = permanent | transient | temporary Reason = term()

Utility function that starts the applications crypto, public_key, and ssh. Default type is temporary. For more information, see the application(3) manual page in kernel.

stop() -> ok | {error, Reason} Stops the ssh application. Reason = term()

Stops the ssh application. For more information, see the application(3) manual page in kernel.

stop_daemon(DaemonRef) -> stop_daemon(Address, Port) -> ok Stops the listener and all connections started by the listener. DaemonRef = ssh_daemon_ref() Address = ip_address() Port = integer()

Stops the listener and all connections started by the listener.

stop_listener(DaemonRef) -> stop_listener(Address, Port) -> ok Stops the listener, but leaves existing connections started by the listener operational. DaemonRef = ssh_daemon_ref() Address = ip_address() Port = integer()

Stops the listener, but leaves existing connections started by the listener operational.