Reference Manual
Release Notes
PDF
Top

SSH
Reference Manual
Version 1.1.8

Expand All
Contract All

Table of Contents

- ssh
  - Top of manual page
  - close/1
  - connect/3
  - connect/4
  - connection_info/2
  - daemon/1
  - daemon/2
  - daemon/3
  - shell/1
  - shell/2
  - shell/3
  - start/0
  - start/1
  - stop/0
  - stop_daemon/1
  - stop_daemon/2
  - stop_listener/1
  - stop_listener/2
- ssh_channel
  - Top of manual page
  - call/2
  - call/3
  - cast/2
  - enter_loop/1
  - init/1
  - reply/2
  - start/4
  - start_link/4
  - CallbackModule:code_change/3
  - CallbackModule:init/1
  - CallbackModule:handle_call/3
  - CallbackModule:handle_cast/2
  - CallbackModule:handle_msg/2
  - CallbackModule:handle_ssh_msg/2
  - CallbackModule:terminate/2
- ssh_connection
  - Top of manual page
  - adjust_window/3
  - close/2
  - exec/4
  - exit_status/3
  - reply_request/4
  - send/3
  - send/4
  - send/4
  - send/5
  - send_eof/2
  - session_channel/2
  - session_channel/4
  - setenv/5
  - shell/2
  - subsystem/4
- ssh_sftp
  - Top of manual page
  - start_channel/1
  - start_channel/2
  - start_channel/2
  - start_channel/3
  - stop_channel/1
  - read_file/2
  - read_file/3
  - write_file/3
  - write_file/4
  - list_dir/2
  - list_dir/3
  - open/3
  - open/4
  - opendir/2
  - opendir/3
  - close/2
  - close/3
  - read/3
  - read/4
  - pread/4
  - pread/5
  - aread/3
  - apread/4
  - write/3
  - write/4
  - pwrite/4
  - pwrite/5
  - awrite/3
  - apwrite/4
  - position/3
  - position/4
  - read_file_info/2
  - read_file_info/3
  - read_link_info/2
  - read_link_info/3
  - write_file_info/3
  - write_file_info/4
  - read_link/2
  - read_link/3
  - make_symlink/3
  - make_symlink/4
  - rename/3
  - rename/4
  - delete/2
  - delete/3
  - make_dir/2
  - make_dir/3
  - del_dir/2
  - del_dir/3
- ssh_sftpd
  - Top of manual page
  - subsystem_spec/1

# ssh

### MODULE

ssh

### MODULE SUMMARY

Main API of the SSH application

### DESCRIPTION

Interface module for the SSH application

### COMMON DATA TYPES

Type definitions that are used more than once in this module:

boolean() = true | false

string() = list of ASCII characters

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() - {N1,N2,N3,N4} % IPv4 | {K1,K2,K3,K4,K5,K6,K7,K8} % IPv6

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

### EXPORTS

close(ConnectionRef) -> ok

Types:

ConnectionRef = ssh_connection_ref()

Closes a ssh connection.

connect(Host, Port, Options) ->
connect(Host, Port, Options, Timeout) -> {ok, ssh_connection_ref()} | {error, Reason}

Types:

Host = string()
Port = integer()
The default is 22, the registered port for SSH.
Options = [{Option, Value}]
Timeout = infinity | integer(milliseconds)

Connects to an SSH server. No channel is started this is done by calling ssh_connect:session_channel/2.

Options are:

{user_dir, String}

  Sets the user directory e.i. the directory containing ssh configuration files for the user such as known_hosts, id_rsa, id_dsa and authorized_key. Defaults to the directory normally referred to as ~/.ssh

{silently_accept_hosts, boolean()}

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

{user_interaction, boolean()}

  If false disables the client to connect to the server if any user interaction is needed such as accepting that the server will 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. Do note that it may not always be desirable to use those options from a security point of view.

{public_key_alg, ssh_rsa | ssh_dsa}

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

{connect_timeout, timeout()}

  Sets a timeout on the transport layer connection. Defaults to infinity.

{user, String}

  Provide a user name. If this option is not given, ssh reads from the environment (LOGNAME or USER on unix, USERNAME on Windows).

{password, string()}

  Provide a password for password authentication. If this option is not given, the user will be asked for a password if the password authentication method is attempted.

{user_auth, Fun/3}

  Provide a fun for password authentication. The fun will be called as fun(User, Password, Opts) and should return true or false.

{key_cb, atom() = KeyCallbackModule}

  Provide a special call-back module for key handling. The call-back module should be modeled after the ssh_file module. The functions that must be exported are: private_host_rsa_key/2, private_host_dsa_key/2, lookup_host_key/3 and add_host_key/3. This is considered somewhat experimental and will be better documented later on.

{fd, file_descriptor()}

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

connection_info(ConnectionRef, [Option]) ->[{Option, Value}]

Types:

Option = client_version | server_version | peer
Value = term()

Retrieves information about a connection.

daemon(Port) ->
daemon(Port, Options) ->
daemon(HostAddress, Port, Options) -> ssh_daemon_ref()

Types:

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

{subsystems, [subsystem_spec()]
  Provides specifications for handling of subsystems. The "sftp" subsystem-spec can be retrieved by calling ssh_sftd:subsystem_spec/1. If the subsystems option in not present the value of [ssh_sftd:subsystem_spec([])] will be used. It is of course possible to set the option to the empty list if you do not want the daemon to run any subsystems at all.
{shell, {Module, Function, Args} | fun(string() = User) - > pid() | fun(string() = User, ip_address() = PeerAddr) -> pid()}
  Defines the read-eval-print loop used when a shell is requested by the client. Example use the erlang shell: {shell, start, []} which is the default behavior.
{ssh_cli,{channel_callback(), channel_init_args()}}
  Provide your own cli implementation, e.i. a channel callback module that implements a shell and command execution. Note that you may customize the shell read-eval-print loop using the option shell which is much less work than implementing your own cli channel.
{system_dir, string()}

  Sets the system directory, containing the host files that identifies the host for ssh. The default is /etc/ssh, note that SSH normally requires the host files there to be readable only by root.

{user_passwords, [{string() = User, string() = Password}]}

  Provide passwords for password authentication.They will be used when someone tries to connect to the server and public key user authentication fails. The option provides a list of valid user names and the corresponding password.

{password, string()}

  Provide a global password that will authenticate any user. From a security perspective this option makes the server very vulnerable.

{pwdfun, fun/2}

  Provide a function for password validation. This is called with user and password as strings, and should return true if the password is valid and false otherwise.

{fd, file_descriptor()}

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

shell(Host) ->
shell(Host, Option) ->
shell(Host, Port, Option) -> _

Types:

Host = string()
Port = integer()
Options - see ssh:connect/3

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

start() ->
start(Type) -> ok | {error, Reason}

Types:

Type = permanent | transient | temporary
Reason = term()

Starts the Ssh application. Default type is temporary. See also application(3) Requires that the crypto application has been started.

stop() -> ok

Stops the Ssh application. See also application(3)

stop_daemon(DaemonRef) ->
stop_daemon(Address, Port) -> ok

Types:

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

Types:

DaemonRef = ssh_daemon_ref()
Address = ip_address()
Port = integer()

Stops the listener, but leaves existing connections started by the listener up and running.