ssh(3)
๐ ssh(3) ๐ โ Erlang Module Definition, but make it a vibe โจ
okay so. ssh(3). main character of the Erlang Module Definition section, no cap. let's get into it ๐ซถ
๐ธ NAME ๐ธ
ssh โ the Main API of the ssh application. yes bestie, the whole entire thing. she does it all ๐
๐ฆ DESCRIPTION ๐ฆ
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. (iconic behaviour honestly โ secure stuff over an insecure network? we love to see it ๐) See ssh 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). both. she's versatile like that ๐
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. Those 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 application. (the user is a process bestie, not a person, we stay humble ๐)
A server-side subsystem (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. Similarly, 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. three steps? bundled?? we love a shortcut โจ
To write your own client channel handler, use the behaviour ssh_client_channel. For server channel handlers use ssh_server_channel behaviour (replaces ssh_daemon_channel). note the glow-up: ssh_daemon_channel is the old name, ssh_server_channel is the new one. periodt.
Both clients and daemons accept options that control 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.
NOTE: See also SSH Application Reference and Examples section. ๐ซ
๐ Keys and files ๐
A number of objects must be present for the SSH application to work. Those 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 completely different storage could be interfaced by writing callback 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. (custom storage? she's flexible fr fr ๐ง)
๐ 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/sshin the filesssh_host_dsa_keyandssh_host_dsa_key.pubssh_host_rsa_keyandssh_host_rsa_key.pubssh_host_ecdsa_keyandssh_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_keysin 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/0 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_dsaandid_dsa.pubid_rsaandid_rsa.pubid_ecdsaandid_ecdsa.pub
โจ DATA TYPES โจ
okay bestie this is the big section. hydrate. we go type by type and nothing gets skipped ๐ง
accept_callback()
accept_callback() ::
fun((PeerName :: string(), fingerprint()) -> boolean()) |
fun((PeerName :: string(),
Port :: inet:port_number(),
fingerprint()) ->
boolean()).
accept_hosts()
accept_hosts() ::
boolean() |
accept_callback() |
{HashAlgoSpec :: fp_digest_alg(), accept_callback()}.
alg_entry()
alg_entry() ::
{kex, [kex_alg()]} |
{public_key, [pubkey_alg()]} |
{cipher, double_algs(cipher_alg())} |
{mac, double_algs(mac_alg())} |
{compression, double_algs(compression_alg())}.
algs_list()
algs_list() :: [alg_entry()].
alive_common_option()
alive_common_option() ::
{alive,
#{count_max := CountMax :: pos_integer(),
interval := Interval :: timeout()}}.
This option is used to configure the alive messages. Alive messages are sent through the encrypted channel and are typically used to detect that a connection became unresponsive. (aka: are you still there bestie?? ๐)
count_max sets the maximum number of alive messages which may be sent without receiving any messages back from the peer. If this threshold is reached the connection will be terminated. interval sets a timeout interval, in milliseconds, after which, if no data has been received from the peer, a message to request a response from the peer is sent.
The default is #{count_max => 3, interval => infinity}, which means that alive messages will not be sent to the peer, since the interval is set to infinity.
No alive messages are sent during renegotiation, however, a timeout derived from the alive parameters is set to ensure that unresponsive connections are terminated. (renegotiation is a no-alive-zone, but don't worry, the timeout still has your back ๐ช)
auth_methods_common_option()
auth_methods_common_option() :: {auth_methods, string()}.
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. (she's free-spirited like that ๐๏ธ)
authentication_client_options()
authentication_client_options() ::
{user, string()} | {password, string()}.
userโ Provides the username. If this option is not given,sshreads from the environment (LOGNAMEorUSERon UNIX,USERNAMEon 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. (yes she will literally ask you. out loud. ๐ฃ๏ธ)
authentication_daemon_options()
authentication_daemon_options() ::
ssh_file:system_dir_daemon_option() |
{auth_method_kb_interactive_data, prompt_texts()} |
{user_passwords, [{UserName :: string(), Pwd :: string()}]} |
{pk_check_user, boolean()} |
{password, string()} |
{pwdfun, pwdfun_2() | pwdfun_4()} |
{no_auth_needed, boolean()}.
callbacks_daemon_options()
callbacks_daemon_options() ::
{failfun,
fun((User :: string(),
Peer :: {inet:ip_address(), inet:port_number()},
Reason :: term()) ->
_)} |
{connectfun,
fun((User :: string(),
Peer :: {inet:ip_address(), inet:port_number()},
Method :: string()) ->
_)} |
{bannerfun, fun((User :: string()) -> binary())}.
connectfunโ Provides a fun to implement your own logging when a user authenticates to the server.failfunโ Provides a fun to implement your own logging when a user fails to authenticate.bannerfunโ Provides a fun to implement the construction of a banner text that is sent at the beginning of the user authentication. The banner will not be sent if the function does not return a binary. (no binary, no banner, sorry bestie ๐ซ)
-opaque channel_id()
Opaque data type representing a channel inside a connection.
Returned by the functions ssh_connection:session_channel/2,4.
(that's a hyphen up top there, -opaque โ she's built different, and she's opaque so don't go poking at her insides ๐)
cipher_alg()
cipher_alg() ::
'aes128-ctr' | 'aes128-gcm@openssh.com' | 'aes192-ctr' |
'aes256-ctr' | 'aes256-gcm@openssh.com' |
'chacha20-poly1305@openssh.com' |
disabled_cipher_alg() |
legacy_cipher_alg().
client_option()
client_option() ::
ssh_file:pubkey_passphrase_client_options() |
host_accepting_client_options() |
authentication_client_options() |
diffie_hellman_group_exchange_client_option() |
connect_timeout_client_option() |
recv_ext_info_client_option() |
gen_tcp:connect_option() |
common_option() |
experimental_client_options().
Options for clients. The individual options are further explained below or by following the hyperlinks.
Note that not every gen_tcp:connect_option/0 is accepted. See set_sock_opts/2 for a list of prohibited options.
Also note that setting a gen_tcp:connect_option/0 could change the socket in a way that impacts the ssh client's behaviour negatively. You use it on your own risk. ๐
bestie I'm serious about that one. on your own risk. that's a direct quote-worthy warning, not me being dramatic (for once). ๐
client_options()
client_options() :: [client_option()].
common_option()
common_option() ::
ssh_file:user_dir_common_option() |
profile_common_option() |
max_idle_time_common_option() |
max_log_item_len_common_option() |
key_cb_common_option() |
disconnectfun_common_option() |
unexpectedfun_common_option() |
ssh_msg_debug_fun_common_option() |
rekey_limit_common_option() |
id_string_common_option() |
pref_public_key_algs_common_option() |
preferred_algorithms_common_option() |
modify_algorithms_common_option() |
auth_methods_common_option() |
inet_common_option() |
fd_common_option() |
alive_common_option().
The options above can be used both in clients and in daemons (servers). They are further explained below. (shared custody options ๐)
common_options()
common_options() :: [common_option()].
compression_alg()
compression_alg() ::
none | 'zlib@openssh.com' | legacy_compression_alg().
and that's part 1 bestie ๐ซถ lowkey a lot but we're literally just getting started โ more coming โจ
conn_info_algs() ๐
conn_info_algs() ::
[{kex, kex_alg()} |
{hkey, pubkey_alg()} |
{encrypt, cipher_alg()} |
{decrypt, cipher_alg()} |
{send_mac, mac_alg()} |
{recv_mac, mac_alg()} |
{compress, compression_alg()} |
{decompress, compression_alg()} |
{send_ext_info, boolean()} |
{recv_ext_info, boolean()}].
That's the algs-info shape, periodt. ๐
conn_info_channels()
conn_info_channels() :: [proplists:proplist()].
A list of property lists. Slay. โจ
connect_timeout_client_option()
connect_timeout_client_option() :: {connect_timeout, timeout()}.
Sets a timeout on the transport layer connect time. For gen_tcp the time is in milli-seconds and the default value is infinity.
And if you're looking for a timeout for the negotiation phase instead? Bestie, that's a whole different thing โ see the parameter Timeout in connect/4. ๐ซถ
connection_info_tuple()
connection_info_tuple() ::
{client_version, version()} |
{server_version, version()} |
{user, string()} |
{peer, {inet:hostname(), ip_port()}} |
{sockname, ip_port()} |
{options, client_options()} |
{algorithms, conn_info_algs()} |
{channels, conn_info_channels()}.
These are the return values from the connection_info/1 and connection_info/2 functions. ๐
NOTE: Note that the options info tuple contains only items with nondefault values. Like, if you didn't change it, it's not showing up here. ๐
connection_ref()
connection_ref() :: pid().
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. ๐ฆ
daemon_info_tuple()
daemon_info_tuple() ::
{port, inet:port_number()} |
{ip, inet:ip_address()} |
{profile, atom()} |
{options, daemon_options()}.
Return values from the daemon_info/1 and daemon_info/2 functions.
NOTE: Again โ the options info tuple contains only items with nondefault values. No defaults sneaking in, no cap. ๐
daemon_option()
daemon_option() ::
subsystem_daemon_option() |
shell_daemon_option() |
exec_daemon_option() |
ssh_cli_daemon_option() |
tcpip_tunnel_out_daemon_option() |
tcpip_tunnel_in_daemon_option() |
authentication_daemon_options() |
diffie_hellman_group_exchange_daemon_option() |
max_initial_idle_time_daemon_option() |
negotiation_timeout_daemon_option() |
hello_timeout_daemon_option() |
hardening_daemon_options() |
callbacks_daemon_options() |
send_ext_info_daemon_option() |
gen_tcp:listen_option() |
common_option() |
experimental_daemon_options().
Options for daemons, bestie. The individual options get explained further down below, or by following the hyperlinks. โจ
Note that not every gen_tcp:listen_option/0 is accepted. See set_sock_opts/2 for a list of prohibited options. ๐ซ
Also note that setting a gen_tcp:listen_option/0 could change the socket in a way that impacts the ssh daemon's behaviour negatively. You use it on your own risk. ๐ญ
daemon_options()
daemon_options() :: [daemon_option()].
daemon_ref() ๐
-opaque daemon_ref()
Opaque data type representing a daemon.
Returned by the functions daemon/1,2,3. ๐
deprecated_exec_opt()
deprecated_exec_opt() :: fun() | mod_fun_args().
Old-style exec specification that are kept for compatibility, but should not be used in new programs. It's giving legacy energy, and not the cute kind. ๐
diffie_hellman_group_exchange_client_option()
diffie_hellman_group_exchange_client_option() ::
{dh_gex_limits,
{Min :: pos_integer(),
I :: pos_integer(),
Max :: pos_integer()}}.
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}. ๐ง
diffie_hellman_group_exchange_daemon_option()
diffie_hellman_group_exchange_daemon_option() ::
{dh_gex_groups,
[explicit_group()] |
explicit_group_file() |
ssh_moduli_file()} |
{dh_gex_limits, {Min :: pos_integer(), Max :: pos_integer()}}.
disabled_cipher_alg()
disabled_cipher_alg() :: 'AEAD_AES_128_GCM' | 'AEAD_AES_256_GCM'.
disabled_mac_alg()
disabled_mac_alg() :: 'AEAD_AES_128_GCM' | 'AEAD_AES_256_GCM'.
Same two names for both, iconique. ๐ธ
disconnectfun_common_option()
disconnectfun_common_option() ::
{disconnectfun, fun((Reason :: term()) -> void | any())}.
Provides a fun to implement your own logging or other handling at disconnects. So when the connection dips, you decide what happens. ๐ฅ
double_algs(AlgType) ๐
double_algs(AlgType) ::
[{client2server, [AlgType]} | {server2client, [AlgType]}] |
[AlgType].
List of algorithms to use in the algorithm negotiation. The default algs_list/0 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]}
]
}
So 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. Bestie, notice the difference, it matters. ๐
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. ๐ญ
WARNING: 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. Periodt. ๐ซ
exec_daemon_option()
exec_daemon_option() :: {exec, exec_spec()}.
exec_fun()
exec_fun() :: 'exec_fun/1'() | 'exec_fun/2'() | 'exec_fun/3'().
The default is disabled. ๐
Value erlang_eval enables evaluation of Erlang terms via exec requests. This works when the shell option is either disabled (no shell) or {shell, start, []} (Erlang shell). It does not work with custom shells.
To restore the behavior from OTP versions prior to OTP @OTP-19969@, configure:
ssh:daemon(Port, [{shell, {shell, start, []}},
{exec, erlang_eval}
| Options])
For new code, consider using {direct, Fun} for more controlled exec handling. โจ
'exec_fun/1'()
'exec_fun/1'() :: fun((Cmd :: string()) -> exec_result()).
'exec_fun/2'()
'exec_fun/2'() ::
fun((Cmd :: string(), User :: string()) -> exec_result()).
'exec_fun/3'()
'exec_fun/3'() ::
fun((Cmd :: string(),
User :: string(),
ClientAddr :: ip_port()) ->
exec_result()).
exec_result()
exec_result() ::
{ok, Result :: term()} | {error, Reason :: term()}.
This option changes how the daemon executes 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. ๐
See the User's Guide section on One-Time Execution for examples.
Error texts are returned on channel-type 1 which usually is piped to stderr on e.g Linux systems. Texts from a successful execution are returned on channel-type 0 and will in similar manner be piped to stdout. The exit-status code is set to 0 for success and 255 for errors. The exact results presented on the client side depends on the client and the client's operating system. ๐ฆ
In case of the {direct, exec_fun()} variant or erlang_eval, all reads from standard_input will be from the received data-events of type 0. Those are sent by the client. Similarly all writes to standard_output will be sent as data-events to the client. An OS shell client like the command ssh will usually use stdin and stdout for the user interface.
The option cooperates with the daemon-option shell in the following way:
- If neither the exec-option nor the shell-option is present: Both default to
disabled. No exec-requests or shell-requests are executed. This is the default behavior since@OTP-19969@. To restore the previous behavior, set{shell, {shell, start, []}}and{exec, erlang_eval}. - If the
exec_spec's value isdisabled(the shell-option may or may not be present): No exec-requests are executed but shell-requests are not affected, they follow theshell_spec's value. - If the exec-option is present and the
exec_specvalue=/=disabled(the shell-option may or may not be present): Theexec_specfun()is called with the same number of parameters as the arity of the fun, and the result is returned to the client. Shell-requests are not affected, they follow theshell_spec's value. - If the
exec_spec's value iserlang_eval, and the shell-option isdisabledor set to the default Erlang shell{shell, start, []}: The default Erlang evaluator is used for exec requests. The result is returned to the client. Shell-requests follow theshell_spec's value. - If the
exec_spec's value iserlang_eval, and the shell-option is present with a value that is neither the default Erlang shell nordisabled: The exec-request is not evaluated and an error message is returned to the client. Shell-requests are executed according to the value of theshell_spec. - If the exec-option is absent (defaults to
disabled), and theshell_spec's value isdisabled: Neither exec-requests nor shell-requests are executed.
If a custom CLI is installed (see the option ssh_cli) the rules above are replaced by those implied by the custom CLI. ๐
NOTE: 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-6 above if conflicting. The old and undocumented style should not be used in new programs. ๐
exec_spec()
exec_spec() ::
{direct, exec_fun()} |
disabled |
deprecated_exec_opt() |
erlang_eval.
experimental_client_options()
experimental_client_options() ::
{keyboard_interact_fun,
fun((Name :: iodata(),
Instruction :: iodata(),
Prompts :: [{Prompt :: iodata(), Echo :: boolean()}]) ->
[Response :: iodata()])} |
experimental_common_options().
Experimental options that should not to be used in products.
Ok so real talk bestie โ the name literally says it. Experimental. Not for products. The maintainers are telling you this to your face. Do not ship it. ๐
experimental_common_options()
experimental_common_options() ::
{transport, {atom(), atom(), atom()}} |
{vsn, {non_neg_integer(), non_neg_integer()}} |
{tstflg, [term()]} |
ssh_file:user_dir_fun_common_option() |
{max_random_length_padding, non_neg_integer()}.
Experimental options that should not to be used in products.
Same energy, same warning, just the "common" flavored batch. ๐ซถ
experimental_daemon_options()
experimental_daemon_options() ::
{infofun, fun()} | experimental_common_options().
Experimental options that should not to be used in products.
The daemon edition of "please don't, I'm begging." ๐ญ
explicit_group()
explicit_group() ::
{Size :: pos_integer(),
G :: pos_integer(),
P :: pos_integer()}.
That's the whole thing, no extra lore attached. โจ
explicit_group_file()
explicit_group_file() :: {file, string()}.
Yep, that's it. A file tag and a string. Short and iconic. ๐
fd_common_option()
fd_common_option() :: {fd, gen_tcp:socket()}.
Allows an existing file-descriptor to be used (passed on to the transport protocol).
So likeโฆ you already have a socket, you just hand it over and let the transport do its thing. Reuse, don't redo. ๐
fingerprint()
fingerprint() :: string() | [string()].
One string, or a whole list of them. Whatever the vibe calls for. ๐ธ
fp_digest_alg()
fp_digest_alg() :: md5 | crypto:sha1() | crypto:sha2().
hardening_daemon_options()
hardening_daemon_options() ::
{max_sessions, pos_integer()} |
{max_channels, pos_integer()} |
{parallel_login, boolean()} |
{minimal_remote_max_packet_size, pos_integer()}.
For more information about hardening, see the Hardening section in the User's Guide chapter.
max_sessions
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.
max_channels
The maximum number of channels with active remote subsystem that are accepted for each connection to this daemon.
By default, this option is not set. This means that the number is not limited.
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.
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.
WARNING: Do not enableparallel_loginswithout protecting the server by other means, for example, by themax_sessionsoption or a firewall configuration. If set totrue, there is no protection against DOS attacks. Bestie. I am so serious. ๐จ
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.
hello_timeout_daemon_option()
hello_timeout_daemon_option() :: {hello_timeout, timeout()}.
Maximum time in milliseconds for the first part of the ssh session setup, the hello message exchange. Defaults to 30000 ms (30 seconds). If the client fails to send the first message within this time, the connection is closed.
For more information about timeouts, see the Timeouts section in the User's Guide Hardening chapter.
host()
host() :: string() | inet:ip_address() | loopback.
host_accepting_client_options()
host_accepting_client_options() ::
{silently_accept_hosts, accept_hosts()} |
{user_interaction, boolean()} |
{save_accepted_host, boolean()} |
{quiet_mode, boolean()}.
silently_accept_hosts
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 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/0. The valuetruewill make the client accept any unknown Host Key without any user interaction. The valuefalsepreserves the default behaviour of asking the user on stdio. - An
accept_callback/0will be called and the boolean return valuetruewill make the client accept the Host Key. A return value offalsewill make the client to reject the Host Key and as a result the connection will be closed. The arguments to thefunare:PeerNameโ a string with the name or address of the remote host.FingerPrintโ the fingerprint of the Host Key ashostkey_fingerprint/1calculates it.
- tuple
{HashAlgoSpec, accept_callback}. TheHashAlgoSpecspecifies which hash algorithm shall be used to calculate the fingerprint used in the call of theaccept_callback/0. TheHashALgoSpecis either an atom or a list of atoms as the first argument inhostkey_fingerprint/2. If it is a list of hash algorithm names, theFingerPrintargument in theaccept_callback/0will be a list of fingerprints in the same order as the corresponding name in theHashAlgoSpeclist.
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.
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.
save_accepted_host
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 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
If true, the client does not print anything on authorization.
Defaults to false
id_string_common_option()
id_string_common_option() ::
{id_string,
string() |
random |
{random, Nmin :: pos_integer(), Nmax :: pos_integer()}}.
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.
inet_common_option()
inet_common_option() :: {inet, inet | inet6}.
IP version to use when the host address is specified as any.
ip_port()
ip_port() :: {inet:ip_address(), inet:port_number()}.
kb_int_fun_3()
kb_int_fun_3() ::
fun((Peer :: ip_port(), User :: string(), Service :: string())
->
kb_int_tuple()).
kb_int_fun_4()
kb_int_fun_4() ::
fun((Peer :: ip_port(),
User :: string(),
Service :: string(),
State :: any()) ->
kb_int_tuple()).
kb_int_tuple()
kb_int_tuple() ::
{Name :: string(),
Instruction :: string(),
Prompt :: string(),
Echo :: boolean()}.
kex_alg()
kex_alg() ::
'diffie-hellman-group-exchange-sha256' |
'diffie-hellman-group14-sha256' |
'diffie-hellman-group16-sha512' |
'diffie-hellman-group18-sha512' | 'curve25519-sha256' |
'curve25519-sha256@libssh.org' | 'curve448-sha512' |
'ecdh-sha2-nistp256' | 'ecdh-sha2-nistp384' |
'ecdh-sha2-nistp521' | 'mlkem768x25519-sha256' |
legacy_kex_alg().
Look at that list. Immaculate. โจ
key_cb_common_option()
key_cb_common_option() ::
{key_cb,
Module :: atom() | {Module :: atom(), Opts :: [term()]}}.
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, []}. See also the manpage of 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.
legacy_cipher_alg()
legacy_cipher_alg() ::
'aes128-cbc' | 'aes192-cbc' | 'aes256-cbc' | '3des-cbc'.
legacy_compression_alg()
legacy_compression_alg() :: zlib.
Deprecated: use'none'or'zlib@openssh.com'instead
Deprecated: the use ofzlibcompression in SSH will be removed in OTP 30.0. Usenoneorzlib@openssh.cominstead.
Not me warning you twice ๐ but like, they said it twice so I'm saying it twice.
legacy_kex_alg()
legacy_kex_alg() ::
'diffie-hellman-group1-sha1' | 'diffie-hellman-group14-sha1' |
'diffie-hellman-group-exchange-sha1'.
legacy_mac_alg() :: 'hmac-sha1-96'.
legacy_pubkey_alg() :: 'ssh-rsa' | 'ssh-dss'.
limit_bytes() :: non_neg_integer() | infinity.
limit_time() :: pos_integer() | infinity.
okay so these two cuties are literally the rekeying limit dials ๐๏ธ โ when does the connection go "aight, new keys pls" and restart the crypto. You can set both a max time and a max amount of data, bestie:
{Minutes, Bytes}โ rekeying kicks off when either of the limits is hit. Whichever one gets there first, no cap.Bytesโ rekeying happens onceBytesnumber of bytes have been transferred, or at the very latest after one hour. โฐ
The moment a rekeying goes down, both the timer and the byte counter get reset back to zero, fresh start โจ. The defaults are one hour and one GByte.
Now for the spicy part ๐ถ๏ธ: if you set Minutes to infinity, that max-time limit will literally never trigger a rekeying. Set Bytes to infinity and it won't rekey after a certain amount of data either. And if you go full chaos mode with {infinity, infinity}, no rekeying will ever be initiated by you. That said ๐ฅ โ rekeying that the peer starts will still happen, so you can't fully stop it, iykyk.
mac_alg() ::
'hmac-sha1' | 'hmac-sha1-etm@openssh.com' | 'hmac-sha2-256' |
'hmac-sha2-512' | 'hmac-sha2-256-etm@openssh.com' |
'hmac-sha2-512-etm@openssh.com' |
disabled_mac_alg() |
legacy_mac_alg().
max_idle_time_common_option() :: {idle_time, timeout()}.
Puts a time-out on a connection when there are no channels open. It defaults to infinity. Unit is milliseconds, bestie ๐ฐ๏ธ.
Lowkey important detail: the timeout isn't active until channels are actually started, so it does not limit the time between the connection being created and the first channel opening. slay.
For more info about timeouts, go check the Timeouts section in the User's Guide Hardening chapter.
max_initial_idle_time_daemon_option() :: {max_initial_idle_time, timeout()}.
Max time in milliseconds for the first channel to start after the authentication negotiation finishes. Defaults to infinity. ๐ธ
For more info about timeouts, see the Timeouts section in the User's Guide Hardening chapter.
max_log_item_len_common_option() :: {max_log_item_len, limit_bytes()}.
Sets a cap on how big a logged item can be, not counting the header. Unit is bytes, and the value defaults to 500. โ๏ธ
mod_args() :: {Module :: atom(), Args :: list()}.
mod_fun_args() :: {Module :: atom(), Function :: atom(), Args :: list()}.
modify_algorithms_common_option() :: {modify_algorithms, modify_algs_list()}.
modify_algs_list() ::
[{append, algs_list()} |
{prepend, algs_list()} |
{rm, algs_list()}].
This one modifies the list of algorithms used in algorithm negotiation. And the tea โ here is that the modifications are applied after the option preferred_algorithms (if it exists) has already been applied. Order matters, bestie.
The algorithm for the modifications works like this:
- Input is the
modify_algs_list/0and a set of algorithmsAobtained from thepreferred_algorithmsoption if it exists, or else fromssh:default_algorithms/0. - The head of the
modify_algs_list/0modifiesA, giving the resultA'.
The possible modifications are:
- Append or prepend supported but not enabled algorithm(s) to the list of algorithms. If the algorithms you want are already in
A, they'll first be removed and then appended or prepended. ๐ - Remove (
rm) one or more algorithms fromA.
- Repeat the modification step with the tail of
modify_algs_list/0and the resultingA'.
If an unsupported algorithm shows up in the modify_algs_list/0, it will be silently ignored ๐คซ.
If you pass more than one modify_algorithms option, the result is undefined. Don't do that, fr fr.
Here's an example of this option:
{modify_algorithms,
[{prepend, [{kex, ['diffie-hellman-group1-sha1']}],
{rm, [{compression, [none]}]}
]
}
The example is saying that:
- the old key exchange algorithm
'diffie-hellman-group1-sha1'should be the main alternative. It'll be the main alternative because it got prepended 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. ๐
negotiation_timeout_daemon_option() :: {negotiation_timeout, timeout()}.
Max time in milliseconds for the authentication negotiation. Defaults to 120000 ms (2 minutes). If the client fails to log in within that window, the connection is closed. ๐ช๐
For more info about timeouts, see the Timeouts section in the User's Guide Hardening chapter.
open_socket() :: gen_tcp:socket().
This socket is supposed to be the result of a gen_tcp:connect or a gen_tcp:accept. And it must be in passive mode โ that means opened with the option {active,false}. no exceptions bestie, passive mode only ๐ง
pref_public_key_algs_common_option() :: {pref_public_key_algs, [pubkey_alg()]}.
A 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's no public key of a specified type available, that corresponding entry is just ignored, nbd. Heads up though: the available set depends on the underlying cryptolib and the current user's public keys.
See also the option user_dir for specifying the path to the user's keys. ๐
preferred_algorithms_common_option() :: {preferred_algorithms, algs_list()}.
profile_common_option() :: {profile, atom()}.
Used together with ip-address and port to uniquely identify an ssh daemon. Super handy in a virtualized environment, where there can be more than one server chillin' on the same ip-address and port ๐ตโ๐ซ. If this property isn't explicitly set, it's assumed that the ip-address and port uniquely identify the SSH daemon.
prompt_texts() :: kb_int_tuple() | kb_int_fun_3() | kb_int_fun_4().
protocol_version() :: {Major :: pos_integer(), Minor :: non_neg_integer()}.
pubkey_alg() ::
'ecdsa-sha2-nistp256' | 'ecdsa-sha2-nistp384' |
'ecdsa-sha2-nistp521' | 'ssh-ed25519' | 'ssh-ed448' |
'rsa-sha2-256' | 'rsa-sha2-512' |
legacy_pubkey_alg().
pwdfun_2() ::
fun((User :: string(), Password :: string() | pubkey) ->
boolean()).
pwdfun_4() ::
fun((User :: string(),
Password :: string() | pubkey,
PeerAddress :: ip_port(),
State :: any()) ->
boolean() |
disconnect |
{boolean(), NewState :: any()}).
๐ auth_method_kb_interactive_data
Sets the text strings that the daemon sends to the client, so they can be shown to the user when using keyboard-interactive authentication. ๐ฌ
If the fun/3 or fun/4 is used, it gets called when the actual authentication happens, which means it can return dynamic data like time, remote ip, etc. โ very main character energy โจ.
The parameter Echo guides the client about whether it needs to hide the password. ๐
The default value is:
{auth_method_kb_interactive_data, {"SSH server", "Enter
password for \""++User++"\"", "password: ", false}>
๐ user_passwords
Provides passwords for password authentication. These passwords are used when someone tries to connect to the server and public key user-authentication fails. The option gives you a list of valid usernames and their corresponding passwords.
โ ๏ธ WARNING: this is very insecure because of the plain-text passwords; it's meant for test purposes. Use the pwdfun option to handle the password checking instead, bestie, pls. ๐ญ
๐ pk_check_user
Enables checking of the client's user name in the server when doing public key authentication. It's disabled by default.
The term "user" is used differently in OpenSSH and SSH in Erlang/OTP โ see more in the User's Guide.
If the option is enabled, and no pwdfun is present, the user name must be present in the user_passwords for the check to succeed โ but the value of the password is not checked. ๐ฏ
In case of a pwdfun checking the user, the atom pubkey is put in the password argument.
๐ password
Provides a global password that authenticates any user. ๐ณ
โ ๏ธ WARNING: intended to facilitate testing. From a security perspective, this option makes the server very vulnerable. do not ship this to prod, i'm begging ๐จ
๐ pwdfun with pwdfun_4/0
Provides a function for password validation. This could be used for calling an external system, or handling passwords stored as hash values. ๐งฎ
This fun can also be used to make delays in authentication tries, for example by calling timer:sleep/1. โณ
And to facilitate, say, 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:
trueif the user and password is validfalseif the user or password is invaliddisconnectif aSSH_MSG_DISCONNECTmessage 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
A third usage is to block login attempts from a misbehaving peer. The State described above can be used for this. The return value disconnect is useful for this. ๐ซ
In case pk_check_user is set, the atom pubkey is put in the password argument when validating a public key login. The pwdfun is then responsible for checking that the user name is valid.
๐ง pwdfun with pwdfun_2/0
Provides a function for password validation. This function is called with user and password as strings, and returns:
trueif the user and password is valid- false if the user or password is invalid ๐
If pk_check_user is set, the atom pubkey gets slid into the password argument when a public key login is being validated. Then pwdfun is the one holding the aux cord โ it's responsible for checking that the user name is valid. โจ
This variant is kept for compatibility. (iykyk โ it's giving legacy, don't @ her)
no_auth_neededโ iftrue, a client gets authenticated with zero password and zero key. No cap, nothing. ๐ซฃ
This option is only for extremely special applications, because the risk of accepting literally any connecting client is high. highkey dangerous.
The default value is false.
recv_ext_info_client_option()
recv_ext_info_client_option() :: {recv_ext_info, boolean()}.
Makes the client tell the server "bestie I accept extension negotiation" โ aka include ext-info-c in the kexinit message it sends. See RFC 8308 for the deets and ssh for a list of currently implemented extensions.
Default value is true, which plays nice with other implementations that don't support ext-info. ๐ซถ
rekey_limit_common_option()
rekey_limit_common_option() ::
{rekey_limit,
Bytes ::
limit_bytes() |
{Minutes :: limit_time(), Bytes :: limit_bytes()}}.
role()
role() :: client | server.
send_ext_info_daemon_option()
send_ext_info_daemon_option() :: {send_ext_info, boolean()}.
Makes the server (daemon) tell the client that the server accepts extension negotiation โ aka include ext-info-s in the kexinit message it sends. See RFC 8308 for the deets and ssh for a list of currently implemented extensions.
Default value is true, compatible with other implementations that don't support ext-info. โจ
shell_daemon_option()
shell_daemon_option() :: {shell, shell_spec()}.
shell_fun()
shell_fun() :: 'shell_fun/1'() | 'shell_fun/2'().
The default is disabled.
To enable the Erlang shell, do this cute lil thing:
ssh:daemon(Port, [{shell, {shell, start, []}} | Options])
'shell_fun/1'()
'shell_fun/1'() :: fun((User :: string()) -> pid()).
'shell_fun/2'()
'shell_fun/2'() ::
fun((User :: string(), PeerAddr :: inet:ip_address()) ->
pid()).
Defines the read-eval-print loop used in a daemon when the client requests a shell. ๐
See the option exec-option for a description of how the daemon runs shell-requests and exec-requests depending on the shell- and exec-options.
shell_spec()
shell_spec() :: mod_fun_args() | shell_fun() | disabled.
software_version()
software_version() :: string().
-opaque ssh_channel_id()
-opaque ssh_channel_id()
ssh_cli_daemon_option()
ssh_cli_daemon_option() :: {ssh_cli, mod_args() | no_cli}.
Lets you serve your own CLI implementation in a daemon. ๐
It's 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. It means less work than implementing an own CLI channel. If ssh_cli is set to no_cli, the CLI channels like shell and exec get disabled, and only subsystem channels are allowed.
-opaque ssh_connection_ref()
-opaque ssh_connection_ref()
-opaque ssh_daemon_ref()
-opaque ssh_daemon_ref()
ssh_moduli_file()
ssh_moduli_file() :: {ssh_moduli_file, string()}.
dh_gex_groupsโ defines the groups the server may choose among whendiffie-hellman-group-exchangeis negotiated. See RFC 4419 for the fine print. The three variants of this option are:{Size=integer(),G=integer(),P=integer()}โ the groups are given explicitly in this list. There may be several elements with the sameSize. In that case, the server will choose one randomly in the negotiatedSize. ๐ฒ{file,filename()}โ the file must have one or more three-tuples{Size=integer(),G=integer(),P=integer()}terminated by a dot. The file is read when the daemon starts.{ssh_moduli_file,filename()}โ the file must be inssh-keygenmoduli file format. The file is read when the daemon starts.
The default list is fetched from the public_key application.
dh_gex_limitsโ limits what a client can ask for indiffie-hellman-group-exchange. The limits will be{MaxUsed = min(MaxClient,Max), MinUsed = max(MinClient,Min)}whereMaxClientandMinClientare the values proposed by a connecting client.
The default value is {0,infinity}.
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.
ssh_msg_debug_fun_common_option()
ssh_msg_debug_fun_common_option() ::
{ssh_msg_debug_fun,
fun((ssh:connection_ref(),
AlwaysDisplay :: boolean(),
Msg :: binary(),
LanguageTag :: binary()) ->
any())}.
Provides a fun so you can implement your own logging of the SSH message SSH_MSG_DEBUG. The last three parameters come from the message, see RFC 4253, section 11.3. The connection_ref/0 is the reference to the connection where the message arrived. The return value from the fun is not checked. โจ
The default behaviour is to 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}
subsystem_daemon_option()
subsystem_daemon_option() :: {subsystems, subsystem_specs()}.
subsystem_spec()
subsystem_spec() :: {Name :: string(), mod_args()}.
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_server_channel (replaces ssh_daemon_channel) behaviour in the daemon. See the section Creating a Subsystem in the User's Guide for more info and an example.
If the subsystems option is not present, the default is an empty list and no subsystems are enabled.
To enable the SFTP subsystem:
ssh:daemon(Port, [{subsystems, [ssh_sftpd:subsystem_spec([])]} | Options])
subsystem_specs()
subsystem_specs() :: [subsystem_spec()].
tcpip_tunnel_in_daemon_option()
tcpip_tunnel_in_daemon_option() ::
{tcpip_tunnel_in,
boolean() |
(Callback ::
fun((HostName :: string(), inet:port_number()) ->
boolean() | denied))}.
Enables (true) or disables (false) the possibility to tunnel a TCP/IP connection in to a server. Disabled per default. ๐ช
Set a Callback function to allow/deny/log tunnel connections.
tcpip_tunnel_out_daemon_option()
tcpip_tunnel_out_daemon_option() :: {tcpip_tunnel_out, boolean()}.
Enables (true) or disables (false) the possibility to tunnel a TCP/IP connection out of a server. Disabled per default. ๐ช
unexpectedfun_common_option()
unexpectedfun_common_option() ::
{unexpectedfun,
fun((Message :: term(), {Host :: term(), Port :: term()}) ->
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.
version()
version() :: {protocol_version(), software_version()}.
๐ FUNCTIONS ๐
close(ConnectionRef) -> ok | {error, term()}
close(ConnectionRef) -> ok | {error, term()}
when ConnectionRef :: connection_ref().
Closes an SSH connection. Bye bestie ๐
connect(Host, Port, Options, NegotiationTimeout)
connect(Host, Port, Options, NegotiationTimeout) ->
{ok, connection_ref()} | {error, term()}
when
Host :: host(),
Port :: inet:port_number(),
Options :: client_options(),
NegotiationTimeout :: timeout().
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. That gets done by calling ssh_connection:session_channel/2,4.
The NegotiationTimeout is in milli-seconds. The default value is infinity or the value of the connect_timeout option, if present. For connection timeout, use the option connect_timeout.
connection_info(ConnectionRef, ItemList | Item)
connection_info(ConnectionRef, ItemList | Item) ->
InfoTupleList | InfoTuple | {error, term()}
when
ConnectionRef :: connection_ref(),
ItemList :: [Item],
Item ::
client_version | server_version |
user | peer | sockname | options |
algorithms | sockname,
InfoTupleList :: [InfoTuple],
InfoTuple :: connection_info_tuple().
Returns information about a connection, intended for e.g. debugging or logging. ๐
When the Key is a single Item, the result is a single InfoTuple.
daemon(any | inet:ip_address(), inet:port_number(), daemon_options())
daemon(any | inet:ip_address(),
inet:port_number(),
daemon_options()) ->
{ok, daemon_ref()} | {error, term()};
(socket, open_socket(), daemon_options()) ->
{ok, daemon_ref()} | {error, term()}.
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 theHostAddressargument 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
HostAddressis an IP-address, that IP-address is the listening address. An'ip'-option will be discarded if present. - if
HostAddressis the atomloopback, the listening address is loopback and a loopback address will be chosen by the underlying layers. An'ip'-option will be discarded if present. - if
HostAddressis the atomanyand no'ip'-option is hanging around, then the listening address isanyand the socket lowkey listens on every address ๐ - if
HostAddressisanyand an'ip'-option is there, the listening address gets set to whatever that'ip'-option says ๐
๐ธ daemon_info โจ
daemon_info(DaemonRef, ItemList | Item) ->
InfoTupleList | InfoTuple | {error, bad_daemon_ref}
when
DaemonRef :: daemon_ref(),
ItemList :: [Item],
Item :: ip | port | profile | options,
InfoTupleList :: [InfoTuple],
InfoTuple :: daemon_info_tuple().
Hands you info about a daemon, bestie โ think debugging or logging energy ๐ซถ like it's giving "tell me everything about this daemon".
When the Key is a single Item, the result is a single InfoTuple โจ
Heads up tho: daemon_info/1 and daemon_info/2 return different types, and that's for compatibility reasons, no cap ๐ฅฒ
๐ daemon_replace_options ๐
daemon_replace_options(DaemonRef, NewUserOptions) ->
{ok, daemon_ref()} | {error, term()}
when
DaemonRef :: daemon_ref(),
NewUserOptions :: daemon_options().
Swaps out the options in a running daemon for the ones in NewUserOptions, periodt. Only connections established after this call are affected โ connections you already had going are not touched, sorry not sorry ๐
NOTE: in the final phase of this function, the listening process gets restarted. Therfore (yes, that's how it's spelled in the original, iconic) a connection attempt to the daemon during this final phase could fail. ๐
The handling of Erlang configurations is described in the User's Guide โ go peek at the chapters Configuration in SSH and Configuring algorithms in SSH ๐
๐ฆ default_algorithms ๐ธ
default_algorithms() -> algs_list().
Returns a key-value list where the keys are the different types of algorithms and the values are the algorithms themselves ๐
See the User's Guide for an example โญ
๐ get_sock_opts โจ
get_sock_opts(ConnectionRef, SocketGetOptions) ->
ok | {error, inet:posix()}
when
ConnectionRef :: connection_ref(),
SocketGetOptions :: [gen_tcp:option_name()].
Grabs the tcp socket option values of the tcp-socket sitting below an ssh connection ๐
This function calls inet:getopts/2, so go read that documentation bestie ๐
๐ hostkey_fingerprint ๐
hostkey_fingerprint(TypeOrTypes, Key) -> StringOrString
when
TypeOrTypes ::
public_key:digest_type() |
[public_key:digest_type()],
Key :: public_key:public_key(),
StringOrString :: string() |
[string()].
hostkey_fingerprint([DigestType], HostKey) ->
[string()]hostkey_fingerprint(DigestType, HostKey) -> string()
Calculates an ssh fingerprint from a public host key, the exact same way openssh does it, no cap ๐
The algorithm in hostkey_fingerprint/1 is md5, being compatible with the older ssh-keygen commands. The string from the second variant gets prepended by the algorithm name in uppercase, just like newer ssh-keygen commands ๐
Examples:
2> ssh:hostkey_fingerprint(Key).
"f5:64:a6:c1:5a:cb:9f:0a:10:46:a2:5c:3e:2f:57:84"
3> ssh:hostkey_fingerprint(md5,Key).
"MD5:f5:64:a6:c1:5a:cb:9f:0a:10:46:a2:5c:3e:2f:57:84"
4> ssh:hostkey_fingerprint(sha,Key).
"SHA1:bSLY/C4QXLDL/Iwmhyg0PGW9UbY"
5> ssh:hostkey_fingerprint(sha256,Key).
"SHA256:aZGXhabfbf4oxglxltItWeHU7ub3Dc31NcNw2cMJePQ"
6> ssh:hostkey_fingerprint([sha,sha256],Key).
["SHA1:bSLY/C4QXLDL/Iwmhyg0PGW9UbY",
"SHA256:aZGXhabfbf4oxglxltItWeHU7ub3Dc31NcNw2cMJePQ"]
๐ฅ set_sock_opts ๐
set_sock_opts(ConnectionRef, SocketOptions) ->
ok | {error, inet:posix()}
when
ConnectionRef :: connection_ref(),
SocketOptions :: [gen_tcp:option()].
Sets tcp socket options on the tcp-socket below an ssh connection ๐ธ
This function calls inet:setopts/2 โ go read that documentation, plus gen_tcp:option/0 ๐
All gen_tcp socket options are allowed except:
activedelivermodeandpacket
Those excluded ones are reserved by the SSH application, so hands off bestie ๐ โโ๏ธ
WARNING: this is an extremely dangerous function. You use it at your own risk. Some options are OS and OS version dependent. Do not use it unless you genuinely know what effect your option values will have on a TCP stream. Some values may literally destroy the functionality of the SSH protocol ๐๐ญ
๐ง shell ๐ซถ
shell(Host, Port, Options) -> _
when
Host :: host(),
Port :: inet:port_number(),
Options :: client_options().
Connects to an SSH server at Host and Port (defaults to 22, iykyk) 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 finally 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) โ so it's giving main character energy, sitting there, vibing, waiting for you ๐
๐ start โญ
start(Type) -> ok | {error, term()}
when Type :: permanent | transient | temporary.
A lil utility function that starts the applications crypto, public_key, and ssh ๐ Default type is temporary. For more info, see the application manual page in Kernel ๐
๐ stop ๐
stop() -> ok | {error, term()}.
Stops the ssh application. For more info, see the application manual page in Kernel ๐
๐ stop_daemon ๐
stop_daemon(any | inet:ip_address(), inet:port_number(), atom()) ->
ok.
Stops the listener and all connections started by the listener ๐ฅ everything, gone, periodt.
If the daemon process does not exist, the call exits the calling process with reason noproc. ๐
๐ธ stop_listener โจ
stop_listener(any | inet:ip_address(), inet:port_number(), term()) ->
ok.
Stops the listener, but leaves the existing connections started by the listener still operational ๐ซถ so it's like, the party's over but everyone already inside gets to stay ๐
๐ฆ tcpip_tunnel_from_server ๐ฅ
tcpip_tunnel_from_server(ConnectionRef, ListenHost, ListenPort,
ConnectToHost, ConnectToPort, Timeout) ->
{ok, TrueListenPort} | {error, term()}
when
ConnectionRef :: connection_ref(),
ListenHost :: host(),
ListenPort :: inet:port_number(),
ConnectToHost :: host(),
ConnectToPort ::
inet:port_number(),
Timeout :: timeout(),
TrueListenPort ::
inet:port_number().
Asks the remote server of ConnectionRef to listen to ListenHost:ListenPort ๐ When someone connects that address, the connection is forwarded in an encrypted channel from the server to the client ๐ The client (that is, at the node that calls this function) then connects to ConnectToHost:ConnectToPort โจ
The returned TrueListenPort is the port that is listened to. It's the same as ListenPort, except when ListenPort = 0 โ in that case a free port gets selected by the underlying OS ๐
Note: in case of an Erlang/OTP SSH server (daemon) as peer, that server must have been started with the option tcpip_tunnel_out to allow the connection ๐
๐ tcpip_tunnel_to_server ๐
tcpip_tunnel_to_server(ConnectionRef, ListenHost, ListenPort,
ConnectToHost, ConnectToPort, Timeout) ->
{ok, TrueListenPort} | {error, term()}
when
ConnectionRef :: connection_ref(),
ListenHost :: host(),
ListenPort :: inet:port_number(),
ConnectToHost :: host(),
ConnectToPort :: inet:port_number(),
Timeout :: timeout(),
TrueListenPort ::
inet:port_number().
Tells the local client to listen to ListenHost:ListenPort ๐ When someone connects to that address, the connection gets forwarded in an encrypted channel to the peer server of ConnectionRef ๐ That server then connects to ConnectToHost:ConnectToPort โจ
The returned TrueListenPort is the port that is listened to. It's the same as ListenPort, except when ListenPort = 0 โ in that case a free port gets selected by the underlying OS ๐ธ
Note: in case of an Erlang/OTP SSH server (daemon) as peer, that server must have been started with the option tcpip_tunnel_in to allow the connection ๐
okay bestie that's literally the whole page ๐ you made it all the way through, iconic behavior, I'm obsessed ๐ซถ
This masterpiece is brought to you by Ericsson AB, and it's ssh version 6.0.5 โ page ssh(3), section 3, serving cutesy Unix energy forever and always โจ๐
๐ฆ where this page comes from
- ubuntu stonking: erlang-doc 1:29.0.6+dfsg-1 ยท Apache-2.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms