From 06a782d7b5868237fa260b293f50646f9883cf33 Mon Sep 17 00:00:00 2001 From: Hans Nilsson Date: Wed, 18 Apr 2018 20:17:49 +0200 Subject: ssh: Use -spec and -type for documentation generation --- lib/ssh/doc/src/Makefile | 8 + lib/ssh/doc/src/configure_algos.xml | 5 +- lib/ssh/doc/src/specs.xml | 12 + lib/ssh/doc/src/ssh.xml | 1790 +++++++++++++++++--------------- lib/ssh/doc/src/ssh_app.xml | 3 +- lib/ssh/doc/src/ssh_channel.xml | 95 +- lib/ssh/doc/src/ssh_client_key_api.xml | 49 +- lib/ssh/doc/src/ssh_connection.xml | 94 +- lib/ssh/doc/src/ssh_server_key_api.xml | 43 +- lib/ssh/doc/src/ssh_sftp.xml | 4 +- lib/ssh/doc/src/using_ssh.xml | 1 + 11 files changed, 1136 insertions(+), 968 deletions(-) create mode 100644 lib/ssh/doc/src/specs.xml (limited to 'lib/ssh/doc/src') diff --git a/lib/ssh/doc/src/Makefile b/lib/ssh/doc/src/Makefile index f54f5e0708..0063484f72 100644 --- a/lib/ssh/doc/src/Makefile +++ b/lib/ssh/doc/src/Makefile @@ -84,12 +84,19 @@ HTML_REF_MAN_FILE = $(HTMLDIR)/index.html TOP_PDF_FILE = $(PDFDIR)/$(APPLICATION)-$(VSN).pdf +SPECS_FILES = $(XML_REF3_FILES:%.xml=$(SPECDIR)/specs_%.xml) + +TOP_SPECS_FILE = specs.xml + # ---------------------------------------------------- # FLAGS # ---------------------------------------------------- XML_FLAGS += DVIPS_FLAGS += +#SPECS_FLAGS = -I../../include -I../../../kernel/include +SPECS_FLAGS = -I../../../public_key/include -I../../../public_key/src -I../../.. + # ---------------------------------------------------- # Targets # ---------------------------------------------------- @@ -111,6 +118,7 @@ clean clean_docs: rm -rf $(HTMLDIR)/* rm -f $(MAN3DIR)/* rm -f $(TOP_PDF_FILE) $(TOP_PDF_FILE:%.pdf=%.fo) + rm -f $(SPECS_FILES) rm -f errs core *~ man: $(MAN3_FILES) $(MAN6_FILES) diff --git a/lib/ssh/doc/src/configure_algos.xml b/lib/ssh/doc/src/configure_algos.xml index dd60324851..15aece8968 100644 --- a/lib/ssh/doc/src/configure_algos.xml +++ b/lib/ssh/doc/src/configure_algos.xml @@ -117,6 +117,7 @@

Due to this, it impossible to list in documentation what algorithms that are available in a certain installation.

There is an important command to list the actual algorithms and their ordering: ssh:default_algorithms/0.

+ 0> ssh:default_algorithms(). [{kex,['ecdh-sha2-nistp384','ecdh-sha2-nistp521', @@ -156,7 +157,7 @@
Replacing the default set: preferred_algorithms -

See the Reference Manual for details

+

See the Reference Manual for details

Here follows a series of examples ranging from simple to more complex.

@@ -301,7 +302,7 @@ First one has to list them with ssh:default_algorithms() and then do changes in the lists.

To facilitate addition or removal of algorithms the option modify_algorithms is available. - See the Reference Manual for details.

+ See the Reference Manual for details.

The option takes a list with instructions to append, prepend or remove algorithms:

diff --git a/lib/ssh/doc/src/specs.xml b/lib/ssh/doc/src/specs.xml new file mode 100644 index 0000000000..3ab4f43aec --- /dev/null +++ b/lib/ssh/doc/src/specs.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/lib/ssh/doc/src/ssh.xml b/lib/ssh/doc/src/ssh.xml index c641badd9a..03078cfd83 100644 --- a/lib/ssh/doc/src/ssh.xml +++ b/lib/ssh/doc/src/ssh.xml @@ -11,8 +11,8 @@ 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 + + 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, @@ -31,203 +31,211 @@ ssh Main API of the ssh application -

Interface module for the ssh application.

-

See ssh(6) for details of supported version, - algorithms and unicode support.

+

This is the interface module for the SSH application. + The Secure Shell (SSH) Protocol is a protocol for secure remote login + and other secure network services over an insecure network. + See ssh(6) for details of supported RFCs, versions, + algorithms and unicode handling. +

+

With the SSH application it is possible to start clients and to start daemons (servers). +

+

Clients are started with + connect/2, + connect/3 or + connect/4. They open an encrypted connection on top of TCP/IP. + In that encrypted connection one or more channels could be opened with + ssh_connection:session_channel/2,4. +

+

Each channel is an isolated "pipe" between a client-side process and a server-side process. Thoose process + pairs could handle for example file transfers (sftp) or remote command execution (shell, exec and/or cli). + If a custom shell is implemented, the user of the client could execute the special commands remotely. Note that + the user is not necessarily a human but probably a system interfacing the SSH app. +

+

A server-side subssystem (channel) server is requested by the client with + ssh_connection:subsystem/4. +

+

A server (daemon) is started with + daemon/1, + daemon/2 or + daemon/3. + Possible channel handlers (subsystems) are declared with the + subsystem option when the daemon is started. +

+

To just run a shell on a remote machine, there are functions that bundles the needed + three steps needed into one: + shell/1,2,3. + Similarily, to just open an sftp (file transfer) connection to a remote machine, the simplest way is to use + ssh_sftp:start_channel/1,2,3. +

+

To write your own client channel handler, use the behaviour + ssh_channel. For own server channel handlers use the ssh_daemon_channel + behaviour: see the note in ssh_channel. +

+

Both clients and daemons accepts options that controls the exact behaviour. Some options are common to both. + The three sets are called + Client Options, + Daemon Options and + Common Options. +

+

The descriptions of the options uses the + Erlang Type Language with explaining text. +

+ +

The User's Guide has examples and a + Getting Started + section. +

+
- OPTIONS -

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.

-

The options are of different kinds:

- - Limits -

which alters limits in the system, for example number of simultaneous login attempts.

- - Timeouts -

which give some defined behaviour if too long time elapses before a given event or action, - for example time to wait for an answer.

- - Callbacks -

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

- - Behaviour -

which changes the systems behaviour.

-
-
- -
- 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() - - as returned by ssh:daemon/[1,2,3]

- - ok_error(OKtype) = -

{ok,OKtype} | {error, term()}

- - ok_error() = -

ok_error(term())

- - ssh_connection_ref() = -

opaque() - as returned by ssh:connect/3

- - ip_address() = -

inet::ip_address()

- - port_number() = -

inet::port_number()

- - 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)

+ Keys and files +

A number of objects must be present for the SSH application to work. + Thoose objects are per default stored in files. + The default names, paths and file formats are the same as for + OpenSSH. Keys could be generated with the ssh-keygen + program from OpenSSH. See the + User's Guide. +

+ +

The paths could easily be changed by options: + user_dir and + system_dir. +

+

A completly different storage could be interfaced by writing call-back modules + using the behaviours + ssh_client_key_api and/or + ssh_server_key_api. + A callback module is installed with the option + key_cb + to the client and/or the daemon. +

+ +
+ Daemons +

The keys are by default stored in files:

+ + Mandatory: one or more Host key(s), both private and public. Default is to + store them in the directory /etc/ssh in the files + + ssh_host_dsa_key and ssh_host_dsa_key.pub + ssh_host_rsa_key and ssh_host_rsa_key.pub + ssh_host_ecdsa_key and ssh_host_ecdsa_key.pub + +

The host keys directory could be changed with the option + system_dir.

+
+ Optional: one or more User's public key in case of publickey authorization. + Default is to store them concatenated in the file .ssh/authorized_keys in the user's home directory. +

The user keys directory could be changed with the option + user_dir.

+
+
+
+ +
+ Clients +

The keys and some other data are by default stored in files in the directory .ssh + in the user's home directory.

+

The directory could be changed with the option + user_dir. +

+ + Optional: a list of Host public key(s) for previously connected hosts. This list + is handled by the SSH application without any need of user assistance. The default + is to store them in the file known_hosts. +

The + host_accepting_client_options() + are associated with this list of keys. +

+
+ Optional: one or more User's private key(s) in case of publickey authorization. + The default files are + + id_dsa and id_dsa.pub + id_rsa and id_rsa.pub + id_ecdsa and id_ecdsa.pub + + +
+
- key_cb() = - -

atom() | {atom(), list()}

-

atom() - Name of the erlang module implementing the behaviours - ssh_client_key_api or - ssh_server_key_api as the - case maybe.

-

list() - List of options that can be passed to the callback module.

-
+
- channel_init_args() = -

list()

+ - algs_list() = -

list( alg_entry() )

+ - alg_entry() = -

{kex, simple_algs()} | {public_key, simple_algs()} | {cipher, double_algs()} | {mac, double_algs()} | {compression, double_algs()}

+ Client Options - simple_algs() = -

list( atom() )

- - double_algs() = -

[{client2serverlist,simple_algs()},{server2client,simple_algs()}] | simple_algs()

+ + + + +

Options for clients. + The individual options are further explained below or by following the hyperlinks. +

+
+
- modify_algs_list() = -

list( {append,algs_list()} | {prepend,algs_list()} | {rm,algs_list()} )

- -
+ + + +

List of user (client) public key algorithms to try to use.

+

The default value is the public_key entry in the list returned by + ssh:default_algorithms/0. +

+

If there is no public key of a specified type available, the corresponding entry is ignored. + Note that the available set is dependent on the underlying cryptolib and current user's public keys. +

+

See also the option user_dir + for specifying the path to the user's keys. +

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

Closes an SSH connection.

+ + + +

If the user's DSA, RSA or ECDSA key is protected by a passphrase, it can be + supplied with thoose options. +

-
- - - connect(Host, Port, Options) -> - connect(Host, Port, Options, Timeout) -> - connect(TcpSocket, Options) -> - connect(TcpSocket, 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()}. - TcpSocket = port() - The socket is supposed to be from gen_tcp:connect or gen_tcp:accept with option {active,false} - + + + + + + + + -

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. -

-
- - -

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

-
- -
-
-
-
-
- boolean()]]>
-
- -
+ silently_accept_hosts -

This option guides the connect function how to act when the connected server presents a Host +

This option guides the connect function on how to act when the connected server presents a Host Key that the client has not seen before. The default is to ask the user with a question on stdio of whether to accept or reject the new Host Key. - See also the option user_dir - for the path to the file known_hosts where previously accepted Host Keys are recorded. -

+ See the option user_dir + for specifying the path to the file known_hosts where previously accepted Host Keys are recorded. + See also the option + key_cb + for the general way to handle keys. +

The option can be given in three different forms as seen above:

- The value is a boolean(). The value true will make the client accept any unknown - Host Key without any user interaction. The value false keeps the default behaviour of asking the - the user on stdio. + The value is a boolean(). + The value true will make the client accept any unknown Host Key without any user interaction. + The value false preserves the default behaviour of asking the user on stdio. - A CallbackFun will be called and the boolean return value true will make the client - accept the Host Key. A return value of false will make the client to reject the Host Key and therefore - also the connection will be closed. The arguments to the fun are: + An accept_callback() will be called and the boolean return value true + will make the client + accept the Host Key. A return value of false will make the client to reject the Host Key and as a + result the connection will be closed. The arguments to the fun are: PeerName - a string with the name or address of the remote host. FingerPrint - the fingerprint of the Host Key as @@ -236,532 +244,334 @@ - A tuple {HashAlgoSpec, CallbackFun}. The HashAlgoSpec specifies which hash algorithm - shall be used to calculate the fingerprint used in the call of the CallbackFun. The HashALgoSpec - is either an atom or a list of atoms as the first argument in - public_key:ssh_hostkey_fingerprint/2. - If it is a list of hash algorithm names, the FingerPrint argument in the CallbackFun will be - a list of fingerprints in the same order as the corresponding name in the HashAlgoSpec list. + A tuple {HashAlgoSpec, accept_callback}. The HashAlgoSpec + specifies which hash algorithm + shall be used to calculate the fingerprint used in the call of the accept_callback(). + The HashALgoSpec + is either an atom or a list of atoms as the first argument in + public_key:ssh_hostkey_fingerprint/2. + If it is a list of hash algorithm names, the FingerPrint argument in the + accept_callback() will be + a list of fingerprints in the same order as the corresponding name in the HashAlgoSpec list.
- - - -

If true, the client saves an accepted host key to avoid the - accept question the next time the same host is connected. If the option - key_cb is not present, the key is saved in the file "known_hosts". -

-

If false, the key is not saved and the key will still be unknown - at the next access of the same host. -

-
- - + + user_interaction

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 + supplying a password.

+

Even if user interaction is allowed it can be suppressed by other options, such as silently_accept_hosts and password. However, those options are not always desirable to use from a security point of view.

+

Defaults to true.

- _}]]> - -

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

-
- - report | skip }]]> - -

Provides a fun to implement your own logging or other action when an unexpected message arrives. - If the fun returns report the usual info report is issued but if skip is returned no - report is generated.

-

Peer is in the format of {Host,Port}.

-
- - - -

List of user (client) public key algorithms to try to use.

-

The default value is the public_key entry in - ssh:default_algorithms/0. -

-

If there is no public key of a specified type available, the corresponding entry is ignored. - Note that the available set is dependent on the underlying cryptolib and current user's public keys. -

-
- - - + save_accepted_host -

List of algorithms to use in the algorithm negotiation. The default algs_list() can - be obtained from default_algorithms/0. +

If true, the client saves an accepted host key to avoid the + accept question the next time the same host is connected. If the option + key_cb + is not present, the key is saved in the file "known_hosts". See option + user_dir for + the location of that file.

-

If an alg_entry() is missing in the algs_list(), the default value is used for that entry.

-

Here is an example of this option:

- -{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]} - ] -} - -

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.

- -

For background and more examples see the User's Guide.

- - -

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.

-
-
- - - - -

Modifies the list of algorithms to use in the algorithm negotiation. The modifications are - applied after the option preferred_algorithms (if existing) is applied.

-

The algoritm for modifications works like this:

- - -

Input is the modify_algs_list() and a set of algorithms A - obtained from the preferred_algorithms option if existing, or else from the - ssh:default_algorithms/0. -

-
- -

The head of the modify_algs_list() modifies A giving the result A'.

-

The possible modifications are:

- - -

Append or prepend supported but not enabled algorithm(s) to the list of - algorithms. If the wanted algorithms already are in A they will first - be removed and then appended or prepended, -

-
- -

Remove (rm) one or more algorithms from A. -

-
-
-
- -

Repeat the modification step with the tail of modify_algs_list() and the resulting - A'. -

-
-
-

If an unsupported algorithm is in the modify_algs_list(), it will be silently ignored

-

If there are more than one modify_algorithms options, the result is undefined.

-

Here is an example of this option:

- -{modify_algorithms, - [{prepend, [{kex, ['diffie-hellman-group1-sha1']}], - {rm, [{compression, [none]}]} - ] -} - -

The example specifies that:

- -

the old key exchange algorithm 'diffie-hellman-group1-sha1' should be - the main alternative. It will be the main alternative since it is prepened to the list

-
-

The compression algorithm none (= no compression) is removed so compression is enforced

-
-
-

For background and more examples see the User's Guide.

-
- - - -

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 {1024, 6144, 8192}. +

If false, the key is not saved and the key will still be unknown + at the next access of the same host.

+

Defaults to true

- + quiet_mode -

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

+

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

+

Defaults to false

+
+
+
- - -

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

-
- - + + + + + user -

Provides a username. If this option is not given, ssh +

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

- + password

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.

- - - - - -

Tell the server that the client accepts extension negotiation. See - Draft-ietf-curdle-ssh-ext-info (work in progress) for details. -

-

Currently implemented extension is server-sig-algs which is the list of the server's preferred - user's public key algorithms. -

-

Default value is true. -

-
- - - -

Module implementing the behaviour ssh_client_key_api. 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'. -

-
- - - -

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(), {ip_address(), port_number()}} | - Sockname::{ip_address(), port_number()} - + + -

Retrieves information about a connection.

+

Sets the three diffie-hellman-group-exchange parameters that guides the connected server in choosing a group. + See + RFC 4419 + for the details. The default value is {1024, 6144, 8192}. +

-
- - - daemon(Port) -> - daemon(Port, Options) -> - daemon(HostAddress, Port, Options) -> - daemon(TcpSocket) -> - daemon(TcpSocket, Options) -> {ok, ssh_daemon_ref()} | {error, atom()} - Starts a server listening for SSH connections - on the given port. - - Port = integer() - HostAddress = ip_address() | any | loopback - Options = [{Option, Value}] - Option = atom() - Value = term() - TcpSocket = port() - The socket is supposed to be from gen_tcp:connect or gen_tcp:accept with option {active,false} - - -

Starts a server listening for SSH connections on the given - port. If the Port is 0, a random free port is selected. See - daemon_info/1 about how to find the selected port number.

- -

Please note that by historical reasons both the HostAddress argument and the inet socket option - ip set the listening address. This is a source of possible inconsistent settings.

+ -

The rules for handling the two address passing options are:

- - if HostAddress is an IP-address, that IP-address is the listening address. - An 'ip'-option will be discarded if present. + + + +

Sets a timeout on the transport layer connect time. + For gen_tcp the time is in milli-seconds and the default + value is infinity. +

+

See the parameter Timeout in connect/4 for + a timeout of the negotiation phase. +

+
+
- if HostAddress is loopback, the listening address - is loopback and an loopback address will be choosen by the underlying layers. - An 'ip'-option will be discarded if present. + + + +

Make the client tell the server that the client accepts extension negotiation, that is, + include ext-info-c in the kexinit message sent. See + RFC 8308 + for details and ssh(6) + for a list of currently implemented extensions. +

+

+ Default value is true which is compatible with other implementations not supporting ext-info. +

+
+
- if HostAddress is any and no 'ip'-option is present, the listening address is - any and the socket will listen to all addresses + + Daemon Options (Server Options) - if HostAddress is any and an 'ip'-option is present, the listening address is - set to the value of the 'ip'-option -
+ + + + +

Options for daemons. + The individual options are further explained below or by following the hyperlinks. +

+
+
-

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.

-
+ + + + + +

Defines a subsystem in the daemon.

+

The subsystem_name is the name that a client requests to start with for example + ssh_connection:subsystem/4. +

+

The channel_callback is the module that implements the ssh_daemon_channel + behaviour in the daemon. See the section + Creating a Subsystem + in the User's Guide for more information and an example. +

+

If the subsystems option is not present, the value of ssh_sftpd:subsystem_spec([]) is used. + This enables the sftp subsystem by default. + 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 in a daemon when a shell is requested by the client. + The default is to use the Erlang shell: +

+

See the option exec + for a description of how the daemon execute exec-requests depending on + the shell- and exec-options.

+
+
+ + + + + + + + +

This option changes how the daemon execute exec-requests from clients. The term in the return value + is formatted to a string if it is a non-string type. No trailing newline is added in the ok-case but in the + error case.

+

Error texts are returned on channel-type 1 which usually is piped to stderr on e.g Linux systems. + Texts from a successful execution will in similar manner be piped to stdout. The exit-status code + is set to 0 for success and -1 for errors. The exact results presented on the client side depends on the + client and the client's operating system. +

+

The option cooperates with the daemon-option shell + in the following way:

+ + 1. If the exec-option is present (the shell-option may or may not be present): -

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

-

See the option exec - for a description of how the daemon execute exec-requests depending on - the shell- and exec-options.

+

The exec-option fun is called with the same number of parameters as the arity of the fun, + and the result is returned to the client. +

- - - -
where: -
exec_spec() = -
fun(Cmd::string()) -> ok_error() -
| fun(Cmd::string(), User::string()) -> ok_error() -
| fun(Cmd::string(), User::string(), ClientAddr::{ip_address(), port_number()}) -> ok_error() -
+ + 2. If the exec-option is absent, but a shell-option is present with the default Erlang shell: -

This option changes how the daemon execute exec-requests from clients. The term in ok_error() - is formatted to a string if it is a non-string type. No trailing newline is added in the ok-case but in the - error case.

-

Error texts are returned on channel-type 1 which usually are piped to stderr on e.g Linux systems. - Texts from a successful execution will in similar manner be piped to stdout. The exit-status code - is set to 0 for success and -1 for errors. The exact results presented on the client side depends on the - client. -

-

The option cooperates with the daemon-option shell - in the following way:

- - 1. If the exec-option is present (the shell-option may or may not be present): - -

The exec-option fun is called with the same number of parameters as the arity of the fun, - and the result is returned to the client. -

-
- - 2. If the exec-option is absent, but a shell-option is present with the default Erlang shell: - -

The default Erlang evaluator is used and the result is returned to the client.

-
- - 3. If the exec-option is absent, but a shell-option is present that is not the default Erlang shell: - -

The exec-request is not evaluated and an error message is returned to the client.

-
- - 4. If neither the exec-option nor the shell-option is present: - -

The default Erlang evaluator is used and the result is returned to the client.

-
-
-

If a custom CLI is installed (see the option ssh_cli) - the rules above are replaced by thoose implied by the custom CLI. -

- -

The exec-option has existed for a long time but has not previously been documented. The old - definition and behaviour are retained but obey the rules 1-4 above if conflicting. - The old and undocumented style should not be used in new programs.

-
+

The default Erlang evaluator is used and the result is returned to the client.

- - - + + 3. If the exec-option is absent, but a shell-option is present that is not the default 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 ssh_cli is set to no_cli, the CLI channels - like shell - and exec - are disabled and only subsystem channels are allowed.

+

The exec-request is not evaluated and an error message is returned to the client.

- + + 4. If neither the exec-option nor the shell-option is present: -

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 - .

+

The default Erlang evaluator is used and the result is returned to the client.

- +
+

If a custom CLI is installed (see the option ssh_cli) + the rules above are replaced by thoose implied by the custom CLI. +

+ +

The exec-option has existed for a long time but has not previously been documented. The old + definition and behaviour are retained but obey the rules 1-4 above if conflicting. + The old and undocumented style should not be used in new programs.

+
+
+
+ + + + +

Provides your own CLI implementation in a daemon.

+

It is a channel callback module that implements a shell + and command execution. The shell's read-eval-print loop can be customized, using the + option shell. This means less work than implementing + an own CLI channel. If ssh_cli is set to no_cli, the CLI channels + like shell + and exec + are disabled and only subsystem channels are allowed.

+
+
+ + + + + + + + + + + system_dir

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.

+ /etc/ssh.

+

For security reasons, this directory is normally accessible only to the root user.

+

See also the option + key_cb + for the general way to handle keys. +

- + auth_method_kb_interactive_data -

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

-

Note that the client is free to use any order and to exclude methods.

-
- - -
where: -
PromptTexts = kb_int_tuple() | fun(Peer::{IP::tuple(),Port::integer()}, User::string(), Service::string()) -> kb_int_tuple() -
kb_int_tuple() = {Name::string(), Instruction::string(), Prompt::string(), Echo::boolean()} -
- -

Sets the text strings that the daemon sends to the client for presentation to the user when using keyboar-interactive 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.

+

Sets the text strings that the daemon sends to the client for presentation to the user when + using keyboard-interactive 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.

The parameter Echo guides the client about need to hide the password.

The default value is: - {auth_method_kb_interactive_data, {"SSH server", "Enter password for \""++User++"\"", "password: ", false}>

+ {auth_method_kb_interactive_data, {"SSH server", "Enter password for \""++User++"\"", "password: ", false}> +

- + user_passwords -

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 +

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.

- + + password -

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

+

Provides a global password that authenticates any user.

+ +

Intended to facilitate testing.

+

From a security perspective this option makes the server very vulnerable.

+
- + pwdfun with pwdfun_4() -

List of algorithms to use in the algorithm negotiation. The default algs_list() can - be obtained from default_algorithms/0. +

Provides a function for password validation. This could used for calling an external system or handeling + passwords stored as hash values.

-

If an alg_entry() is missing in the algs_list(), the default value is used for that entry.

-

Here is an example of this option:

- -{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]} - ] -} - -

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.

- -

For background and more examples see the User's Guide.

+

This fun can also be used to make delays in authentication tries for example by calling + timer:sleep/1.

+

To facilitate for instance counting of failed tries, + the State variable could be used. This state is per connection only. The first time the pwdfun + is called for a connection, the State variable has the value undefined. +

+ +

The fun should return: +

+ + true if the user and password is valid + false if the user or password is invalid + disconnect if a SSH_MSG_DISCONNECT message should be sent immediately. It will + be followed by a close of the underlying tcp connection. + {true, NewState:any()} if the user and password is valid + {false, NewState:any()} if the user or password is invalid + - -

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.

-
+

A third usage is to block login attempts from a missbehaving peer. The State described above + can be used for this. The return value disconnect is useful for this.

- - + pwdfun with pwdfun_2() -

Modifies the list of algorithms to use in the algorithm negotiation. The modifications are - applied after the option preferred_algorithms is applied (if existing)

-

The possible modifications are to:

- -

Append or prepend supported but not enabled algorithm(s) to the list of - algorithms.

If the wanted algorithms already are in the list of algorithms, they will first - be removed and then appended or prepended. -

-
-

Remove (rm) one or more algorithms from the list of algorithms.

+

Provides a function for password validation. This function is called with user and password + as strings, and returns:

+ + true if the user and password is valid + false if the user or password is invalid -

If an unsupported algorithm is in the list, it will be silently ignored

- -

Here is an example of this option:

- -{modify_algorithms, - [{prepend, [{kex, ['diffie-hellman-group1-sha1']}], - {rm, [{compression, [none]}]} - ] -} - -

The example specifies that:

- -

the old key exchange algorithm 'diffie-hellman-group1-sha1' should be - the main alternative. It will be the main alternative since it is prepened to the list

-
-

The compression algorithm none (= no compression) is removed so compression is enforced

-
-
-

For background and more examples see the User's Guide.

+

This variant is kept for compatibility.

+
+
+
- + + + + + + + + dh_gex_groups

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: + See + RFC 4419 + for details. The three variants of this option are:

{Size=integer(),G=integer(),P=integer()} @@ -783,7 +593,7 @@

- + dh_gex_limits

Limits what a client can ask for in diffie-hellman-group-exchange. The limits will be @@ -794,57 +604,29 @@

If MaxUsed < MinUsed in a key exchange, it will fail with a disconnect.

-

See RFC 4419 for the function of the Max and Min values.

-
- - boolean() | disconnect | {boolean(),any()} }]]> - -

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: -

- - true if the user and password is valid and - false otherwise. - -

This fun can also be used to make delays in authentication tries for example by calling - timer:sleep/1. To facilitate counting of failed tries - the State variable could be used. This state is per connection only. The first time the pwdfun - is called for a connection, the State variable has the value undefined. - The pwdfun can return - in addition to the values above - a new state - as: -

- - {true, NewState:any()} if the user and password is valid or - {false, NewState:any()} if the user or password is invalid - -

A third usage is to block login attempts from a missbehaving peer. The State described above - can be used for this. In addition to the responses above, the following return value is introduced: -

- - disconnect if the connection should be closed immediately after sending a SSH_MSG_DISCONNECT - message. - -
- - 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.

-

This option ({pwdfun,fun/2}) is the same as a subset of the previous - ({pwdfun,fun/4}). It is kept for compatibility.

+

See + RFC 4419 + for the function of the Max and Min values.

+
+
+
- - -

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. -

-
+ + + +

Maximum time in milliseconds for the authentication negotiation. + Defaults to 120000 ms (2 minutes). If the client fails to log in within this time, + the connection is closed. +

+
+
- + + + + + max_sessions

The maximum number of simultaneous sessions that are accepted at any time for this daemon. This includes sessions that are being authorized. @@ -864,7 +646,7 @@

- + max_channels

The maximum number of channels with active remote subsystem that are accepted for each connection to this daemon

@@ -872,8 +654,7 @@

- - + parallel_login

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. @@ -890,171 +671,543 @@ - + minimal_remote_max_packet_size -

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

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

+ +
+
+
+ + + + + + connectfun + +

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

+
- + failfun -

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. -

+

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

+
+
+
- - -

Send a list of extensions to the client if the client has asked for it. See - Draft-ietf-curdle-ssh-ext-info (work in progress) for details. -

-

Currently implemented extension is sending server-sig-algs which is the list of the server's preferred - user's public key algorithms. -

-

Default value is true. -

-
+ + + +

Make the server (daemon) tell the client that the server accepts extension negotiation, that is, + include ext-info-s in the kexinit message sent. See + RFC 8308 + for details and ssh(6) + for a list of currently implemented extensions. +

+

Default value is true which is compatible with other implementations not supporting ext-info. +

+
+
- - + + Options common to clients and daemons + + + +

The options above can be used both in clients and in daemons (servers). They are further explained below.

+
+
+ + + + +

Sets the user directory. That is, the directory containing ssh configuration + files for the user, such as + known_hosts, id_rsa, id_dsa>, id_ecdsa and authorized_key. + Defaults to the directory normally referred to as ~/.ssh. +

+

See also the option + key_cb + for the general way to handle keys. +

+
+
+ + + + +

Used together with ip-address and port 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 ip-address and + port. If this property is not explicitly set, it is + assumed that the the ip-address and port + uniquely identifies the SSH daemon. +

+
+
+ + + + +

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

+
+
+ + + + +

Sets a limit, in bytes, when rekeying is to be initiated. + Defaults to once per each GB and once per hour.

+
+
+ + + + +

Module implementing the behaviour + ssh_client_key_api and/or + ssh_server_key_api. + 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'. +

+

The Opts defaults to [] when only the Module is specified. +

+

The default value of this option is {ssh_file, []}. +

+

A call to the call-back function F will be

+ + Module:F(..., [{key_cb_private,Opts}|UserOptions]) + +

where ... are arguments to F as in + ssh_client_key_api and/or + ssh_server_key_api. + The UserOptions are the options given to ssh:connect, ssh:shell or ssh:daemon. +

+ +
+
+ + + + +

Provides a fun to implement your own logging when the peer disconnects.

+
+
+ + + + +

Provides a fun to implement your own logging or other action when an unexpected message arrives. + If the fun returns report the usual info report is issued but if skip is returned no + report is generated.

+
+
+ + + + +

Provide a fun to implement your own logging of the SSH message SSH_MSG_DEBUG. + The last three parameters are from the message, see + RFC 4253, section 11.3. + The connection_ref() 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}

+
+
+ + + + +

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. +

+

The value {random, Nmin, Nmax} will make a random string with at least Nmin characters and + at most Nmax characters. +

+
+
+ + + + + + + + + + + + + +

List of algorithms to use in the algorithm negotiation. The default algs_list() can + be obtained from default_algorithms/0. +

+

If an alg_entry() is missing in the algs_list(), the default value is used for that entry.

+

Here is an example of this option:

+ + {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]} + ] + } + +

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.

+ +

For background and more examples see the User's Guide.

+ +

If an algorithm name occurs more than once in a list, the behaviour is undefined. The tags in the property lists + are also assumed to occur at most one time. +

+ + +

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.

+
+
+
+ + + + + +

Modifies the list of algorithms to use in the algorithm negotiation. The modifications are + applied after the option preferred_algorithms (if existing) is applied.

+

The algoritm for modifications works like this:

+ -

Module implementing the behaviour ssh_server_key_api. 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'. +

Input is the modify_algs_list() and a set of algorithms A + obtained from the preferred_algorithms option if existing, or else from the + ssh:default_algorithms/0.

- - {profile, atom()} -

Used together with ip-address and port 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 ip-address and - port. If this property is not explicitly set, it is - assumed that the the ip-address and port - uniquely identifies the SSH daemon. -

+

The head of the modify_algs_list() modifies A giving the result A'.

+

The possible modifications are:

+ + +

Append or prepend supported but not enabled algorithm(s) to the list of + algorithms. If the wanted algorithms already are in A they will first + be removed and then appended or prepended, +

+
+ +

Remove (rm) one or more algorithms from A. +

+
+
- - - -

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.

+

Repeat the modification step with the tail of modify_algs_list() and the resulting + A'. +

- _}]]> - -

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

+
+

If an unsupported algorithm is in the modify_algs_list(), it will be silently ignored

+

If there are more than one modify_algorithms options, the result is undefined.

+

Here is an example of this option:

+ + {modify_algorithms, + [{prepend, [{kex, ['diffie-hellman-group1-sha1']}], + {rm, [{compression, [none]}]} + ] + } + +

The example specifies that:

+ +

the old key exchange algorithm 'diffie-hellman-group1-sha1' should be + the main alternative. It will be the main alternative since it is prepened to the list

- _}]]> - -

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

+

The compression algorithm none (= no compression) is removed so compression is enforced

+
+

For background and more examples see the User's Guide.

+
+
- report | skip }]]> - -

Provides a fun to implement your own logging or other action when an unexpected message arrives. - If the fun returns report the usual info report is issued but if skip is returned no - report is generated.

-

Peer is in the format of {Host,Port}.

-
- - -

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

-
+ + + +

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

+
+
- _}]]> - -

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}

-
+ + + +

Comma-separated string that determines which authentication methods that the client shall + support and in which order they are tried. Defaults to "publickey,keyboard-interactive,password" +

+

Note that the client is free to use any order and to exclude methods. +

+
+
-
-
-
+ + + +

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

+
+
- - daemon_info(Daemon) -> {ok, [DaemonInfo]} | {error,Error} - Get info about a daemon - - DaemonInfo = {port,Port::pos_integer()} | {listen_address, any|ip_address()} | {profile,atom()} - Port = integer() - Error = bad_daemon_ref - + + Other data types + + + + + + + + + -

Returns a key-value list with information about the daemon. For now, only the listening port is returned. This is intended for the case the daemon is started with the port set to 0.

+
+ + + + + + + + + + + + + + + + +

The socket is supposed to be result of a gen_tcp:connect + or a gen_tcp:accept. The socket must be in passive + mode (that is, opened with the option {active,false}). +

+
+
+ + + + +

Opaque data type representing a daemon.

+

Returned by the functions daemon/1,2,3.

+
+
+ + + connection_ref() + +

Opaque data type representing a connection between a client and a server (daemon).

+

Returned by the functions + connect/2,3,4 and + ssh_sftp:start_channel/2,3. +

+
+
+ + + + +

Opaque data type representing a channel inside a connection.

+

Returned by the functions + ssh_connection:session_channel/2,4. +

+
+
+ + + + opaque_client_options + opaque_daemon_options + opaque_common_options + + + + +

Opaque types that define experimental options that are not to be used in products.

+
+
+ + + + + + + + + + Closes an SSH connection. +

Closes an SSH connection.

+ + + + connect(Host, Port, Options) -> Result + connect(Host, Port, Options, NegotiationTimeout) -> Result + connect(TcpSocket, Options) -> Result + connect(TcpSocket, Options, NegotiationTimeout) -> Result + Connects to an SSH server. + + Host = host() + Port = inet:port_number() + Options = client_options() + TcpSocket = open_socket() + NegotiationTimeout = timeout() + Result = {ok, connection_ref()} | {error, term()} + + +

Connects to an SSH server at the Host on Port. +

+

As an alternative, an already open TCP socket could be passed to the function in TcpSocket. + The SSH initiation and negotiation will be initiated on that one with the SSH that should be at the + other end. +

+

No channel is started. This is done by calling + ssh_connection:session_channel/[2, 4]. +

+

The NegotiationTimeout is in milli-seconds. The default value is infinity. + For connection timeout, use the option + connect_timeout. +

+
+
+ + + + + Retrieves information about a connection. + +

Retrieves information about a connection. The list Keys defines which information that + is returned.

+
+
+ + + + daemon(Port | TcpSocket) -> Result + daemon(Port | TcpSocket, Options) -> Result + daemon(HostAddress, Port, Options) -> Result + Starts a server listening for SSH connections. + + Port = integer() + TcpSocket = open_socket() + Options = daemon_options() + HostAddress = host() | any + Result = {ok, daemon_ref()} | {error, atom()} + + +

Starts a server listening for SSH connections on the given port. If the Port is 0, + a random free port is selected. See daemon_info/1 + about how to find the selected port number. +

+

As an alternative, an already open TCP socket could be passed to the function in TcpSocket. + The SSH initiation and negotiation will be initiated on that one when an SSH starts at the other end + of the TCP socket. +

+

For a description of the options, see Daemon Options. +

+

Please note that by historical reasons both the HostAddress argument and the + gen_tcp connect_option() {ip,Address} + set the listening address. This is a source of possible inconsistent settings. +

+

The rules for handling the two address passing options are:

+ + if HostAddress is an IP-address, that IP-address is the listening address. + An 'ip'-option will be discarded if present. + + if HostAddress is the atom loopback, the listening address + is loopback and an loopback address will be choosen by the underlying layers. + An 'ip'-option will be discarded if present. + + if HostAddress is the atom any and no 'ip'-option is present, the listening address is + any and the socket will listen to all addresses + + if HostAddress is any and an 'ip'-option is present, the listening address is + set to the value of the 'ip'-option + +
+
+ + + + + Get info about a daemon + +

Returns a key-value list with information about the daemon.

+
+
+ + - default_algorithms() -> algs_list() + Get a list declaring the supported algorithms

Returns a key-value list, where the keys are the different types of algorithms and the values are the - algorithms themselves. An example:

- -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> - + algorithms themselves.

+

See the User's Guide for + an example.

+ - shell(Host) -> - shell(Host, Option) -> - shell(Host, Port, Option) -> - shell(TcpSocket) -> _ - Starts an interactive shell over an SSH server. + shell(Host | TcpSocket) -> Result + shell(Host | TcpSocket, Options) -> Result + shell(Host, Port, Options) -> Result + Starts an interactive shell on a remote SSH server. - Host = string() - Port = integer() - Options - see ssh:connect/3 - TcpSocket = port() - The socket is supposed to be from gen_tcp:connect or gen_tcp:accept with option {active,false} + Host = host() + TcpSocket = open_socket() + Port = inet:port_number() + Options = client_options() + Result = ok | {error, Reason::term()} -

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, +

Connects to an SSH server at Host and Port (defaults to 22) and starts an + interactive shell on that remote host. +

+

As an alternative, an already open TCP socket could be passed to the function in TcpSocket. + The SSH initiation and negotiation will be initiated on that one and finaly a shell will be started + on the host at the other end of the TCP socket. +

+

For a description of the options, see Client Options.

+

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. @@ -1064,11 +1217,8 @@ - stop() -> ok | {error, Reason} + Stops the ssh application. - - Reason = term() -

Stops the ssh application. For more information, see the application(3) @@ -1077,34 +1227,22 @@ - 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. -

Stops the listener and all connections started by - the listener.

+

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. -

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

+

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

diff --git a/lib/ssh/doc/src/ssh_app.xml b/lib/ssh/doc/src/ssh_app.xml index faee9ef992..6d180a5272 100644 --- a/lib/ssh/doc/src/ssh_app.xml +++ b/lib/ssh/doc/src/ssh_app.xml @@ -333,7 +333,8 @@ RFC 8332, Use of RSA Keys with SHA-256 and SHA-512 in the Secure Shell (SSH) Protocol. - RFC 8308, Extension Negotiation in the Secure Shell (SSH) Protocol. + + RFC 8308, Extension Negotiation in the Secure Shell (SSH) Protocol.

Implemented are:

The Extension Negotiation Mechanism diff --git a/lib/ssh/doc/src/ssh_channel.xml b/lib/ssh/doc/src/ssh_channel.xml index 7b598494f7..0355f7bf52 100644 --- a/lib/ssh/doc/src/ssh_channel.xml +++ b/lib/ssh/doc/src/ssh_channel.xml @@ -46,6 +46,7 @@ the ssh applications supervisor tree.

+

When implementing an ssh subsystem, use -behaviour(ssh_daemon_channel) instead of -behaviour(ssh_channel). The reason is that the only relevant callback functions for subsystems are @@ -55,33 +56,6 @@

-
- 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() = -

list of ASCII characters

- timeout() = -

infinity | integer() in milliseconds

- ssh_connection_ref() = -

opaque() -as returned by - ssh:connect/3 or sent to an SSH channel process

- ssh_channel_id() = -

integer()

- ssh_data_type_code() = -

1 ("stderr") | 0 ("normal") are - the valid values, - see RFC 4254 - Section 5.2

-
-
- call(ChannelRef, Msg) -> @@ -89,7 +63,7 @@ Makes a synchronous call to a channel. ChannelRef = pid() - As returned by ssh_channel:start_link/4 + As returned by start_link/4 Msg = term() Timeout = timeout() Reply = term() @@ -113,7 +87,7 @@ ChannelRef and returns ok. ChannelRef = pid() - As returned by ssh_channel:start_link/4 + As returned by start_link/4 Msg = term() @@ -131,7 +105,7 @@ Makes an existing process an ssh_channel process. State = term() - as returned by ssh_channel:init/1 + as returned by init/1

Makes an existing process an ssh_channel @@ -141,7 +115,7 @@ one of the start functions in proc_lib, see the proc_lib(3) manual page in STDLIB. The user is responsible for any initialization of the process - and must call ssh_channel:init/1. + and must call init/1.

@@ -160,18 +134,21 @@ The following options must be present:

- + {channel_cb, atom()}

The module that implements the channel behaviour.

- + {init_args(), list()}

The list of arguments to the init function of the callback module.

- -

Reference to the ssh connection as returned by ssh:connect/3

+ {cm, ssh:connection_ref()} +

Reference to the ssh connection as returned by + ssh:connect/3. +

- -

Id of the ssh channel.

+ {channel_id, ssh:channel_id()} +

Id of the ssh channel as returned by + ssh_connection:session_channel/2,4. +

@@ -179,8 +156,8 @@ user. The user only needs to call if the channel process needs to be started with help of proc_lib instead of calling - ssh_channel:start/4 or - ssh_channel:start_link/4.

+ start/4 or + start_link/4.

@@ -201,26 +178,31 @@ the callback function handle_call/3. Reply is an arbitrary term, which is given back to the client as the return value of - ssh_channel:call/[2,3].

+ call/[2,3].

- + start(SshConnection, ChannelId, ChannelCb, CbInitArgs) -> start_link(SshConnection, ChannelId, ChannelCb, CbInitArgs) -> {ok, ChannelRef} | {error, Reason} Starts a process that handles an SSH channel. - SshConnection = ssh_connection_ref() - ChannelId = ssh_channel_id() + SshConnection = ssh:connection_ref() + As returned by ssh:connect/3 + + ChannelId = ssh:channel_id() As returned by ssh_connection:session_channel/[2,4]. + ChannelCb = atom() Name of the module implementing the service-specific parts of the channel. + CbInitArgs = [term()] Argument list for the init function in the callback module. + ChannelRef = pid() @@ -295,7 +277,7 @@ initial channel state if the initializations succeed. Args = term() - Last argument to ssh_channel:start_link/4. + Last argument to start_link/4. State = term() Reason = term() @@ -311,24 +293,24 @@ Module:handle_call(Msg, From, State) -> Result Handles messages sent by calling - ssh_channel:call/[2,3]. + call/[2,3]. Msg = term() From = opaque() Is to be used as argument to - ssh_channel:reply/2 + reply/2 State = term() Result = {reply, Reply, NewState} | {reply, Reply, NewState, timeout()} | {noreply, NewState} | {noreply , NewState, timeout()} | {stop, Reason, Reply, NewState} | {stop, Reason, NewState} Reply = term() - Will be the return value of ssh_channel:call/[2,3] + Will be the return value of call/[2,3] NewState = term() Reason = term()

Handles messages sent by calling - ssh_channel:call/[2,3] + call/[2,3]

For more detailed information on time-outs,, see Section CALLBACK TIME-OUTS.

@@ -338,7 +320,7 @@ Module:handle_cast(Msg, State) -> Result Handles messages sent by calling - ssh_channel:cact/2. + cast/2. Msg = term() State = term() @@ -349,7 +331,7 @@

Handles messages sent by calling - ssh_channel:cast/2. + cast/2.

For more detailed information on time-outs, see Section CALLBACK TIME-OUTS.

@@ -364,7 +346,7 @@ call, or cast messages sent to the channel. Msg = timeout | term() - ChannelId = ssh_channel_id() + ChannelId = ssh:channel_id() State = term() @@ -376,11 +358,10 @@ function and all channels are to handle the following message.

- + {ssh_channel_up, ssh:channel_id(), ssh:connection_ref()}

This is the first message that the channel receives. It is sent just before the ssh_channel:init/1 function + marker="#init-1">init/1 function returns successfully. This is especially useful if the server wants to send a message to the client without first receiving a message from it. If the message is not @@ -397,7 +378,7 @@ Handles ssh connection protocol messages. Msg = ssh_connection:event() - ChannelId = ssh_channel_id() + ChannelId = ssh:channel_id() State = term() @@ -410,7 +391,7 @@ ssh_channel behavior.

- + {closed, ssh:channel_id()}

The channel behavior sends a close message to the other side, if such a message has not already been sent. Then it terminates the channel with reason normal.

diff --git a/lib/ssh/doc/src/ssh_client_key_api.xml b/lib/ssh/doc/src/ssh_client_key_api.xml index 98a1676ca4..9fc54341ed 100644 --- a/lib/ssh/doc/src/ssh_client_key_api.xml +++ b/lib/ssh/doc/src/ssh_client_key_api.xml @@ -41,7 +41,7 @@ see the ssh(6) application manual.

-
+ + + + + + +

Options provided to ssh:connect/[3,4]. +

+

The option list given in the + key_cb + option is available with the key key_cb_private. +

+
+
+
- Module:add_host_key(HostNames, Key, ConnectOptions) -> ok | {error, Reason} + Module:add_host_key(HostNames, PublicHostKey, ConnectOptions) -> ok | {error, Reason} Adds a host key to the set of trusted host keys. - HostNames = string() - Description of the host that owns the PublicKey. + HostNames = string() + Description of the host that owns the PublicHostKey. - Key = public_key() - Normally an RSA, DSA or ECDSA public key, but handling of other public keys can be added. + PublicHostKey = public_key:public_key() + Of ECDSA keys, only the Normally an RSA, DSA or ECDSA public key, but handling of other public keys can be added. - ConnectOptions = proplists:proplist() - Options provided to ssh:connect/[3,4]. The option list given in - the key_cb option is available with the key key_cb_private. - Reason = term(). + ConnectOptions = client_key_cb_options()

Adds a host key to the set of trusted host keys.

@@ -95,18 +106,16 @@ Module:is_host_key(Key, Host, Algorithm, ConnectOptions) -> Result Checks if a host key is trusted. - Key = public_key() + Key = public_key:public_key() Normally an RSA, DSA or ECDSA public key, but handling of other public keys can be added. Host = string() Description of the host. - Algorithm = public_key_algorithm() + Algorithm = ssh:pubkey_alg() Host key algorithm. - ConnectOptions = proplists:proplist() - Options provided to ssh:connect/[3,4]. The option list given in - the key_cb option is available with the key key_cb_private. + ConnectOptions = client_key_cb_options() Result = boolean() @@ -120,14 +129,12 @@ {ok, PrivateKey} | {error, Reason} Fetches the users public key matching the Algorithm. - Algorithm = public_key_algorithm() + Algorithm = ssh:pubkey_alg() Host key algorithm. - ConnectOptions = proplists:proplist() - Options provided to ssh:connect/[3,4]. The option list given in - the key_cb option is available with the key key_cb_private. + ConnectOptions = client_key_cb_options() - PrivateKey = private_key() + PrivateKey = public_key:private_key() Private key of the user matching the Algorithm. Reason = term() diff --git a/lib/ssh/doc/src/ssh_connection.xml b/lib/ssh/doc/src/ssh_connection.xml index 72830de04d..cfe5385eb4 100644 --- a/lib/ssh/doc/src/ssh_connection.xml +++ b/lib/ssh/doc/src/ssh_connection.xml @@ -43,7 +43,7 @@ which are received as messages by the remote channel. If the receiving channel is an Erlang process, the messages have the format - . + . If the ssh_channel behavior is used to implement the channel process, these messages are handled by handle_ssh_msg/2.

@@ -63,10 +63,10 @@

list of ASCII characters

timeout() =

infinity | integer() in milliseconds

- ssh_connection_ref() = + connection_ref() =

opaque() -as returned by ssh:connect/3 or sent to an SSH channel processes

- ssh_channel_id() = + channel_id() =

integer()

ssh_data_type_code() =

1 ("stderr") | 0 ("normal") are @@ -75,7 +75,7 @@ ssh_request_status() =

success | failure

event() = -

{ssh_cm, ssh_connection_ref(), ssh_event_msg()}

+

{ssh_cm, connection_ref(), ssh_event_msg()}

ssh_event_msg() =

data_events() | status_events() | terminal_events()

reason() = @@ -86,12 +86,12 @@ data_events() - +

Data has arrived on the channel. This event is sent as a result of calling ssh_connection:send/[3,4,5].

- +

Indicates that the other side sends no more data. This event is sent as a result of calling ssh_connection:send_eof/2. @@ -103,7 +103,7 @@ - +

A signal can be delivered to the remote process/service using the following message. Some systems do not support signals, in which case they are to ignore this message. There is @@ -111,7 +111,7 @@ referred to are on OS-level and not something generated by an Erlang program.

-

A remote execution can terminate violently because of a signal. @@ -119,7 +119,7 @@ values, see RFC 4254 Section 6.10, which shows a special case of these signals.

- +

When the command running at the other end terminates, the following message can be sent to return the exit status of the command. A zero exit_status usually means that the command @@ -127,7 +127,7 @@ ssh_connection:exit_status/3.

- +

This event is sent as a result of calling ssh_connection:close/2. Both the handling of this event and sending it are taken care of by the @@ -149,14 +149,14 @@ with the boolean value of WantReply as the second argument.

-

Environment variables can be passed to the shell/command to be started later. This event is sent as a result of calling ssh_connection:setenv/5.

- ssh_connection:shell/2.

-

When the window (terminal) size changes on the client side, it can send a message to the server side to inform it of the new dimensions. No API function generates this event.

-

This message requests that the server starts execution of the given command. This event is sent as a result of calling adjust_window(ConnectionRef, ChannelId, NumOfBytes) -> ok Adjusts the SSH flow control window. - ConnectionRef = ssh_connection_ref() - ChannelId = ssh_channel_id() + ConnectionRef = connection_ref() + ChannelId = channel_id() NumOfBytes = integer() @@ -224,8 +224,8 @@ close(ConnectionRef, ChannelId) -> ok Sends a close message on the channel ChannelId. - ConnectionRef = ssh_connection_ref() - ChannelId = ssh_channel_id() + ConnectionRef = connection_ref() + ChannelId = channel_id()

A server- or client-channel process can choose to close their session by @@ -244,8 +244,8 @@ {error, reason()} Requests that the server starts the execution of the given command. - ConnectionRef = ssh_connection_ref() - ChannelId = ssh_channel_id() + ConnectionRef = connection_ref() + ChannelId = channel_id() Command = string() Timeout = timeout() @@ -256,27 +256,27 @@ request is a one-time execution that closes the channel when it is done.

- N x {ssh_cm, ssh_connection_ref(), - {data, ssh_channel_id(), ssh_data_type_code(), Data :: binary()}} + N x {ssh_cm, connection_ref(), + {data, channel_id(), ssh_data_type_code(), Data :: binary()}}

The result of executing the command can be only one line or thousands of lines depending on the command.

- 0 or 1 x {ssh_cm, ssh_connection_ref(), {eof, ssh_channel_id()}} + 0 or 1 x {ssh_cm, connection_ref(), {eof, channel_id()}}

Indicates that no more data is to be sent.

0 or 1 x {ssh_cm, - ssh_connection_ref(), {exit_signal, - ssh_channel_id(), ExitSignal :: string(), ErrorMsg :: string(), LanguageString :: string()}} + connection_ref(), {exit_signal, + channel_id(), ExitSignal :: string(), ErrorMsg :: string(), LanguageString :: string()}}

Not all systems send signals. For details on valid string values, see RFC 4254, Section 6.10

- 0 or 1 x {ssh_cm, ssh_connection_ref(), {exit_status, - ssh_channel_id(), ExitStatus :: integer()}} + 0 or 1 x {ssh_cm, connection_ref(), {exit_status, + channel_id(), ExitStatus :: integer()}}

It is recommended by the SSH Connection Protocol to send this message, but that is not always the case.

- 1 x {ssh_cm, ssh_connection_ref(), - {closed, ssh_channel_id()}} + 1 x {ssh_cm, connection_ref(), + {closed, channel_id()}}

Indicates that the ssh_channel started for the execution of the command has now been shut down.

@@ -287,8 +287,8 @@ exit_status(ConnectionRef, ChannelId, Status) -> ok Sends the exit status of a command to the client. - ConnectionRef = ssh_connection_ref() - ChannelId = ssh_channel_id() + ConnectionRef = connection_ref() + ChannelId = channel_id() Status = integer() @@ -304,8 +304,8 @@ Sends an SSH Connection Protocol pty_req, to allocate a pseudo-terminal. - ConnectionRef = ssh_connection_ref() - ChannelId = ssh_channel_id() + ConnectionRef = connection_ref() + ChannelId = channel_id() Options = proplists:proplist() @@ -342,10 +342,10 @@ reply_request(ConnectionRef, WantReply, Status, ChannelId) -> ok Sends status replies to requests that want such replies. - ConnectionRef = ssh_connection_ref() + ConnectionRef = connection_ref() WantReply = boolean() Status = ssh_request_status() - ChannelId = ssh_channel_id() + ChannelId = channel_id()

Sends status replies to requests where the requester has @@ -364,8 +364,8 @@ ok | {error, timeout} | {error, closed} Sends channel data. - ConnectionRef = ssh_connection_ref() - ChannelId = ssh_channel_id() + ConnectionRef = connection_ref() + ChannelId = channel_id() Data = binary() Type = ssh_data_type_code() Timeout = timeout() @@ -383,8 +383,8 @@ send_eof(ConnectionRef, ChannelId) -> ok | {error, closed} Sends EOF on channel ChannelId. - ConnectionRef = ssh_connection_ref() - ChannelId = ssh_channel_id() + ConnectionRef = connection_ref() + ChannelId = channel_id()

Sends EOF on channel ChannelId.

@@ -394,10 +394,10 @@ session_channel(ConnectionRef, Timeout) -> session_channel(ConnectionRef, InitialWindowSize, - MaxPacketSize, Timeout) -> {ok, ssh_channel_id()} | {error, reason()} + MaxPacketSize, Timeout) -> {ok, channel_id()} | {error, reason()} Opens a channel for an SSH session. - ConnectionRef = ssh_connection_ref() + ConnectionRef = connection_ref() InitialWindowSize = integer() MaxPacketSize = integer() Timeout = timeout() @@ -415,8 +415,8 @@ Environment variables can be passed to the shell/command to be started later. - ConnectionRef = ssh_connection_ref() - ChannelId = ssh_channel_id() + ConnectionRef = connection_ref() + ChannelId = channel_id() Var = string() Value = string() Timeout = timeout() @@ -433,8 +433,8 @@ Requests that the user default shell (typically defined in /etc/passwd in Unix systems) is to be executed at the server end. - ConnectionRef = ssh_connection_ref() - ChannelId = ssh_channel_id() + ConnectionRef = connection_ref() + ChannelId = channel_id()

Is to be called by a client channel process to request that the user default @@ -452,8 +452,8 @@ {error, reason()} Requests to execute a predefined subsystem on the server. - ConnectionRef = ssh_connection_ref() - ChannelId = ssh_channel_id() + ConnectionRef = connection_ref() + ChannelId = channel_id() Subsystem = string() Timeout = timeout() diff --git a/lib/ssh/doc/src/ssh_server_key_api.xml b/lib/ssh/doc/src/ssh_server_key_api.xml index c6808b95d1..cf3b1d319f 100644 --- a/lib/ssh/doc/src/ssh_server_key_api.xml +++ b/lib/ssh/doc/src/ssh_server_key_api.xml @@ -41,7 +41,7 @@ see the ssh(6) application manual.

-
+ + + + + +

Options provided to ssh:daemon/2,3. +

+

The option list given in the + key_cb + option is available with the key key_cb_private. +

+
+
+
+ Module:host_key(Algorithm, DaemonOptions) -> {ok, Key} | {error, Reason} Fetches the host’s private key. - Algorithm = public_key_algorithm() + Algorithm = ssh:pubkey_alg() Host key algorithm. - DaemonOptions = proplists:proplist() - Options provided to ssh:daemon/[2,3]. The option list given in - the key_cb option is available with the key key_cb_private. - Key = private_key() | crypto:engine_key_ref() + + DaemonOptions = daemon_key_cb_options() + + PrivateKey = public_key:private_key() + | crypto:engine_key_ref() + + Private key of the host matching the Algorithm. It may be a reference to a 'ssh-rsa', rsa-sha2-* or 'ssh-dss' (NOT ecdsa) key stored in a loaded Engine. + Reason = term() @@ -93,16 +111,17 @@ - Module:is_auth_key(Key, User, DaemonOptions) -> Result + Module:is_auth_key(PublicUserKey, User, DaemonOptions) -> Result Checks if the user key is authorized. - Key = public_key() + PublicUserKey = public_key:public_key() Normally an RSA, DSA or ECDSA public key, but handling of other public keys can be added + User = string() User owning the public key. - DaemonOptions = proplists:proplist() - Options provided to ssh:daemon/[2,3]. The option list given in - the key_cb option is available with the key key_cb_private. + + DaemonOptions = daemon_key_cb_options() + Result = boolean() diff --git a/lib/ssh/doc/src/ssh_sftp.xml b/lib/ssh/doc/src/ssh_sftp.xml index 129426a6d5..60f643d052 100644 --- a/lib/ssh/doc/src/ssh_sftp.xml +++ b/lib/ssh/doc/src/ssh_sftp.xml @@ -59,7 +59,7 @@

- ssh_connection_ref() = + connection_ref() =

opaque() - as returned by ssh:connect/3

@@ -546,7 +546,7 @@ Starts an SFTP client. Host = string() - ConnectionRef = ssh_connection_ref() + ConnectionRef = connection_ref() Port = integer() TcpSocket = port() The socket is supposed to be from gen_tcp:connect or gen_tcp:accept with option {active,false} diff --git a/lib/ssh/doc/src/using_ssh.xml b/lib/ssh/doc/src/using_ssh.xml index ab307624e6..bde2aaaf99 100644 --- a/lib/ssh/doc/src/using_ssh.xml +++ b/lib/ssh/doc/src/using_ssh.xml @@ -298,6 +298,7 @@ ok = erl_tar:close(HandleRead),
+ Creating a Subsystem

A small ssh subsystem that echoes N bytes can be implemented as shown -- cgit v1.2.3