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

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

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

    <title>SSH</title>
    <prepared></prepared>
    <docno></docno>
    <checked></checked>
    <date></date>
    <rev></rev>
    <file>ssh_app.xml</file>
  </header>
  <app>SSH</app>
  <appsummary>The ssh application implements the Secure Shell (SSH) protocol and
  provides an SSH File Transfer Protocol (SFTP) client and server.</appsummary>
  <description>
    <p>The <c>ssh</c> application is an implementation of the SSH protocol in Erlang.
    <c>ssh</c> offers API functions to write customized SSH clients and servers as well as
    making the Erlang shell available over SSH. An SFTP client, <c>ssh_sftp</c>, and server,
    <c>ssh_sftpd</c>, are also included.</p>
  </description>

   <section>
    <title>DEPENDENCIES</title>
    <p>The <c>ssh</c> application uses the applications
    <seeerl marker="public_key:public_key">public_key</seeerl> and
    <seeerl marker="crypto:crypto">crypto</seeerl> 
    to handle public keys and encryption. Hence, these
    applications must be loaded for the <c>ssh</c> application to work. The call
    <seemfa marker="ssh#start/0">ssh:start/0</seemfa> will do the necessary
    calls to 
    <seemfa marker="kernel:application#start/1">application:start/1,2</seemfa>
    before it starts the <c>ssh</c> itself.
    </p>
  </section>

   <section>
    <title>CONFIGURATION</title>

    <p>The SSH application uses Configuration Parameters.
    Where to set them are described in
    <seefile marker="kernel:config">config User's Guide</seefile> with
    SSH details in
    <seeguide marker="ssh:configurations">Configuration in SSH</seeguide>.
    </p>
    <p>Some special configuration files from OpenSSH are also used:</p>
    <list type="bulleted">
      <item><c>known_hosts</c></item>
      <item><c>authorized_keys</c></item>
      <item><c>authorized_keys2</c></item>
      <item><c>id_dsa</c> <i>(supported but disabled by default)</i></item>
      <item><c>id_rsa</c> <i>(SHA1 sign/verify are supported but disabled by default from OTP-24)</i></item>
      <item><c>id_ecdsa</c></item>
      <item><c>id_ed25519</c></item>
      <item><c>id_ed448</c></item>
      <item><c>ssh_host_dsa_key</c> <i>(supported but disabled by default)</i></item>
      <item><c>ssh_host_rsa_key</c> <i>(SHA1 sign/verify are supported but disabled by default from OTP-24)</i></item>
      <item><c>ssh_host_ecdsa_key</c></item>
      <item><c>ssh_host_ed25519_key</c></item>
      <item><c>ssh_host_ed448_key</c></item>
    </list>
      <p>By default, <c>ssh</c> looks for <c>id_*</c>,
      <c>known_hosts</c>, and <c>authorized_keys</c> in <c>~/.ssh</c>,
      and for the ssh_host_*_key files in <c>/etc/ssh</c>. These locations can be changed
      by the options
      <seetype marker="ssh_file#user_dir_common_option"><c>user_dir</c></seetype> and
      <seetype marker="ssh_file#system_dir_daemon_option"><c>system_dir</c></seetype>.
      More about where to set them is described in
      <seeguide marker="ssh:configurations">Configuration in SSH</seeguide>.
      </p>
      <p>Public key handling can also be customized through a callback module that
      implements the behaviors
      <seeerl marker="ssh_client_key_api">ssh_client_key_api</seeerl> and
      <seeerl marker="ssh_server_key_api">ssh_server_key_api</seeerl>.
      </p>
      <p>See also the default callback module documentation in
      <seeerl marker="ssh_file">ssh_file</seeerl>.
      </p>
      <p>Disabled public key algorithms can be enabled with the
	<seetype marker="ssh:ssh#preferred_algorithms_common_option">preferred_algorithms</seetype>
	or
	<seetype marker="ssh:ssh#modify_algorithms_common_option">modify_algorithms</seetype>
	options.
	See <seeguide marker="configure_algos#example-9">Example 9</seeguide> in
	<seeguide marker="configure_algos">Configuring algorithms in SSH</seeguide>
	for a description.
      </p>

  </section>
  <section>
    <title>Public Keys</title>
    <p><c>id_*</c> are the users private key files.
	Notice that the public key is part of the private key so the <c>ssh</c>
	application does not use the <c>id_*.pub</c> files. These are
	for the user's convenience when it is needed to convey the user's
	public key.
      </p>
    <p>See <seeerl marker="ssh_file#FILE-id_STAR">ssh_file</seeerl> for details.</p>
  </section>
 <section>
    <title>Known Hosts</title>
    <p>The <c>known_hosts</c> file contains a list of approved servers and
      their public keys. Once a server is listed, it can be verified
      without user interaction.
    </p>
    <p>See <seeerl marker="ssh_file#FILE-known_hosts">ssh_file</seeerl> for details.</p>
  </section>
 <section>
    <title>Authorized Keys</title>
    <p>The <c>authorized_key</c> file keeps track of the user's authorized
      public keys. The most common use of this file is to let users
      log in without entering their password, which is supported by the
      Erlang <c>ssh</c> daemon.
      </p>
    <p>See <seeerl marker="ssh_file#FILE-authorized_keys">ssh_file</seeerl> for details.</p>
  </section>
 <section>
    <title>Host Keys</title>
    <p>RSA, DSA (if enabled), ECDSA, ED25519 and ED448 host keys are supported and are
    expected to be found in files named <c>ssh_host_rsa_key</c>,
    <c>ssh_host_dsa_key</c>, <c>ssh_host_ecdsa_key</c>,
    <c>ssh_host_ed25519_key</c> and  <c>ssh_host_ed448_key</c>.
    </p>
    <p>See <seeerl marker="ssh_file#FILE-ssh_host_STAR_key">ssh_file</seeerl> for details.</p>
  </section>
  <section>
    <title>ERROR LOGGER AND EVENT HANDLERS</title>
    <p>The <c>ssh</c> application uses the default <seeerl marker="kernel:error_logger">OTP error logger</seeerl> to log unexpected errors or print information about special events.</p>
  </section>

  <section>
    <marker id="supported"/>
    <title>SUPPORTED SPECIFICATIONS AND STANDARDS</title>
    <p>The supported SSH version is 2.0.</p>
  </section>
  <section>
    <title>Algorithms</title>
    <p>The actual set of algorithms may vary depending on which OpenSSL crypto library that is installed on the machine.
    For the list on a particular installation, use the command
    <seemfa marker="ssh:ssh#default_algorithms/0">ssh:default_algorithms/0</seemfa>. 
    The user may override the default algorithm configuration both on the server side and the client side.
    See the options
    <seetype marker="ssh:ssh#preferred_algorithms_common_option">preferred_algorithms</seetype>
    and
    <seetype marker="ssh:ssh#modify_algorithms_common_option">modify_algorithms</seetype>
    in the <seemfa marker="ssh:ssh#daemon/1">ssh:daemon/1,2,3</seemfa> and
    <seemfa marker="ssh:ssh#connect/3">ssh:connect/3,4</seemfa> functions.
    </p>

    <p>Supported algorithms are (in the default order):</p>
    <marker id="supported_algos"></marker>
    <taglist>
      <tag>Key exchange algorithms</tag>
      <item>
	<list type="bulleted">
	  <item>ecdh-sha2-nistp384</item>
	  <item>ecdh-sha2-nistp521</item>
	  <item>ecdh-sha2-nistp256</item>
	  <item>diffie-hellman-group-exchange-sha256</item>
	  <item>diffie-hellman-group16-sha512</item>
	  <item>diffie-hellman-group18-sha512</item>
	  <item>diffie-hellman-group14-sha256</item>
	  <item>curve25519-sha256</item>
	  <item>curve25519-sha256@libssh.org</item>
	  <item>curve448-sha512</item>
	</list>
	<p>The following unsecure <c>SHA1</c> algorithms are now disabled by default:</p>
	<list>
	  <item>(diffie-hellman-group14-sha1)</item>
	  <item>(diffie-hellman-group-exchange-sha1)</item>
	  <item>(diffie-hellman-group1-sha1)</item>
	</list>
	<p>They can be enabled with the
	<seetype marker="ssh:ssh#preferred_algorithms_common_option">preferred_algorithms</seetype>
	or
	<seetype marker="ssh:ssh#modify_algorithms_common_option">modify_algorithms</seetype>
	options.  Use for example the Option value <c>{modify_algorithms, [{append, [{kex,['diffie-hellman-group1-sha1']}]}]}</c>)</p>
      </item>

      <tag>Public key algorithms</tag>
      <item>
	<list type="bulleted">
	  <item>ecdsa-sha2-nistp384</item>
	  <item>ecdsa-sha2-nistp521</item>
	  <item>ecdsa-sha2-nistp256</item>
	  <item>ssh-ed25519</item>
	  <item>ssh-ed448</item>
	  <item>rsa-sha2-256</item>
	  <item>rsa-sha2-512</item>
	</list>
	<p>The following unsecure <c>SHA1</c> algorithms are supported but disabled by default:</p>
	<list>
	  <item>(ssh-dss)</item>
	  <item>(ssh-rsa)</item>
	</list>
	<p>See 
	Disabled public key algorithms can be enabled with the
	<seetype marker="ssh:ssh#preferred_algorithms_common_option">preferred_algorithms</seetype>
	or
	<seetype marker="ssh:ssh#modify_algorithms_common_option">modify_algorithms</seetype>
	options.
	See <seeguide marker="configure_algos#example-9">Example 9</seeguide> in
	<seeguide marker="configure_algos">Configuring algorithms in SSH</seeguide>
	for a description.
	</p>
      </item>

      <tag>MAC algorithms</tag>
      <item>
	<list type="bulleted">
	  <item>hmac-sha2-256-etm@openssh.com</item>
	  <item>hmac-sha2-512-etm@openssh.com</item>
	  <item>hmac-sha1-etm@openssh.com</item>
	  <item>hmac-sha2-256</item>
	  <item>hmac-sha2-512</item>
	  <item>hmac-sha1</item>
	</list>
	<p>The following unsecure <c>SHA1</c> algorithm is disabled by default:</p>
	<list>
	  <item>(hmac-sha1-96)</item>
	</list>
	<p>It can be enabled with the
	<seetype marker="ssh:ssh#preferred_algorithms_common_option">preferred_algorithms</seetype>
	or
	<seetype marker="ssh:ssh#modify_algorithms_common_option">modify_algorithms</seetype>
	options.  Use for example the Option value <c>{modify_algorithms, [{append, [{mac,['hmac-sha1-96']}]}]}</c>)</p>
      </item>

      <tag>Encryption algorithms (ciphers)</tag>
      <item>
	<list type="bulleted">
	  <item>chacha20-poly1305@openssh.com</item>
          <item>aes256-gcm@openssh.com</item>
	  <item>aes256-ctr</item>
	  <item>aes192-ctr</item>
          <item>aes128-gcm@openssh.com</item>
	  <item>aes128-ctr</item>
	  <item>aes256-cbc</item>
	  <item>aes192-cbc</item>
	  <item>aes128-cbc</item>
	  <item>3des-cbc</item>
	  <item>(AEAD_AES_128_GCM, not enabled per default)</item>
          <item>(AEAD_AES_256_GCM, not enabled per default)</item>
	</list>
	<p>See the text at the description of <seeapp marker="#rfc5647_note">the rfc 5647 further down</seeapp>
	for more information regarding AEAD_AES_*_GCM.
	</p>
	<p>Following the internet de-facto standard, the cipher and mac algorithm AEAD_AES_128_GCM is selected when the
	cipher aes128-gcm@openssh.com is negotiated. The cipher and mac algorithm AEAD_AES_256_GCM is selected when the
	cipher aes256-gcm@openssh.com is negotiated.
	</p>
      </item>
	
      <tag>Compression algorithms</tag>
      <item>
	<list type="bulleted">
	  <item>none</item>
	  <item>zlib@openssh.com</item>
	  <item>zlib</item>
	</list>
      </item>
    </taglist>
  </section>
  <section>
    <title>Unicode support</title>
    <p>Unicode filenames are supported if the emulator and the underlying OS support it. See section DESCRIPTION in the
      <seeerl marker="kernel:file">file</seeerl> manual page in Kernel for information about this subject.
    </p>
    <p>The shell and the cli both support unicode.
    </p>
  </section>

  <section>
    <title>Rfcs</title>
    <p>The following rfc:s are supported:</p>
    <list type="bulleted">
      <item><url href="https://tools.ietf.org/html/rfc4251">RFC 4251</url>, The Secure Shell (SSH) Protocol Architecture.
      <p>Except</p>
      <list type="bulleted">
	<item>9.4.6 Host-Based Authentication</item>
	<item>9.5.2 Proxy Forwarding</item>
	<item>9.5.3 X11 Forwarding</item>
      </list>
      <p/>
      </item>

      <item><url href="https://tools.ietf.org/html/rfc4252">RFC 4252</url>, The Secure Shell (SSH) Authentication Protocol.
      <p>Except</p>
      <list type="bulleted">
	<item>9. Host-Based Authentication: "hostbased"</item>
      </list>
      <p/>
      </item>

      <item><url href="https://tools.ietf.org/html/rfc4253">RFC 4253</url>, The Secure Shell (SSH) Transport Layer Protocol.
      <p>Except</p>
      <list type="bulleted">
	<item>8.1.  diffie-hellman-group1-sha1</item>
	<item>6.6.  Public Key Algorithms
	<list type="bulleted">
	  <item>ssh-dss</item>
	  <item>ssh-rsa</item>
	</list>
	</item>
      </list>
      <p>They are disabled by default as they now are regarded insecure, but they can be enabled with the
      <seetype marker="ssh:ssh#preferred_algorithms_common_option">preferred_algorithms</seetype>
      or
      <seetype marker="ssh:ssh#modify_algorithms_common_option">modify_algorithms</seetype>
      options.
      See <seeguide marker="configure_algos#example-8">Example 8</seeguide> (diffie-hellman-group1-sha1)
      and
      <seeguide marker="configure_algos#example-9">Example 9</seeguide> (ssh-dss)
      in
      <seeguide marker="configure_algos">Configuring algorithms in SSH</seeguide>
      for descriptions.
      </p>
      </item>

      <item><url href="https://tools.ietf.org/html/rfc4254">RFC 4254</url>, The Secure Shell (SSH) Connection Protocol.
      <p>Except</p>
      <list type="bulleted">
	<item>6.3. X11 Forwarding</item>
	<item>7. TCP/IP Port Forwarding</item>
      </list>
      <p/>
      </item>

      <item><url href="https://tools.ietf.org/html/rfc4256">RFC 4256</url>, Generic Message Exchange Authentication for
      the Secure Shell Protocol (SSH).
      <p>Except</p>
      <list type="bulleted">
	<item><c>num-prompts > 1</c></item>
	<item>password changing</item>
	<item>other identification methods than userid-password</item>
	</list>
      <p/>
      </item>

      <item><url href="https://tools.ietf.org/html/rfc4419">RFC 4419</url>,
      Diffie-Hellman Group Exchange for the Secure Shell (SSH) Transport Layer Protocol.
      <p>Except</p>
      <list type="bulleted">
	<item>4.1.  diffie-hellman-group-exchange-sha1</item>
      </list>
      <p>It is disabled by defaultas as it now is regarded insecure, but it can be enabled with the
      <seetype marker="ssh:ssh#preferred_algorithms_common_option">preferred_algorithms</seetype>
      or
      <seetype marker="ssh:ssh#modify_algorithms_common_option">modify_algorithms</seetype>
      options.
      </p>
      </item>

      <item><url href="https://tools.ietf.org/html/rfc4716">RFC 4716</url>, The Secure Shell (SSH) Public Key File Format.
      <p/>
      </item>

      <item><url href="https://tools.ietf.org/html/rfc5647">RFC 5647</url>, AES Galois Counter Mode for
      the Secure Shell Transport Layer Protocol.
      <p><marker id="rfc5647_note"/>There is an ambiguity in the synchronized selection of cipher and mac algorithm. 
      This is resolved by OpenSSH in the ciphers aes128-gcm@openssh.com and aes256-gcm@openssh.com which are implemented.
      If the explicit ciphers and macs AEAD_AES_128_GCM or AEAD_AES_256_GCM are needed, 
      they could be enabled with the options
      <seetype marker="ssh:ssh#preferred_algorithms_common_option">preferred_algorithms</seetype>
      or
      <seetype marker="ssh:ssh#modify_algorithms_common_option">modify_algorithms</seetype>.
      </p>
      <warning>
	<p>
	  If the client or the server is not Erlang/OTP, it is the users responsibility to check that 
	  other implementation has the same interpretation of AEAD_AES_*_GCM as the Erlang/OTP SSH before
	  enabling them. The  aes*-gcm@openssh.com variants are always safe to use since they lack the
	  ambiguity.
	</p>
      </warning>
      <p>The second paragraph in section 5.1 is resolved as:</p>
      <list type="ordered">
	<item>If the negotiated cipher is AEAD_AES_128_GCM, the mac algorithm is set to  AEAD_AES_128_GCM.</item>
	<item>If the negotiated cipher is AEAD_AES_256_GCM, the mac algorithm is set to  AEAD_AES_256_GCM.</item>
	<item>If the mac algorithm is AEAD_AES_128_GCM, the cipher is set to AEAD_AES_128_GCM.</item>
	<item>If the mac algorithm is AEAD_AES_256_GCM, the cipher is set to AEAD_AES_256_GCM.</item>
      </list>
      <p>The first rule that matches when read in order from the top is applied</p>
      </item>
	
      <item><url href="https://tools.ietf.org/html/rfc5656">RFC 5656</url>, Elliptic Curve Algorithm Integration in 
      the Secure Shell Transport Layer.
      <p>Except</p>
      <list type="bulleted">
	<item>5.   ECMQV Key Exchange</item>
	<item>6.4. ECMQV Key Exchange and Verification Method Name</item>
	<item>7.2. ECMQV Message Numbers</item>
	<item>10.2. Recommended Curves</item>
      </list>
      <p/>
      </item>
      
      <item><url href="https://tools.ietf.org/html/rfc6668">RFC 6668</url>, SHA-2 Data Integrity Verification for
      the Secure Shell (SSH) Transport Layer Protocol
      <p>Comment: Defines hmac-sha2-256 and hmac-sha2-512
      </p>
      </item>

      <item><url href="https://tools.ietf.org/html/draft-ietf-curdle-ssh-kex-sha2">Draft-ietf-curdle-ssh-kex-sha2 (work in progress)</url>, Key Exchange (KEX) Method Updates and Recommendations for Secure Shell (SSH).
      <p>Deviations:</p>
      <list type="bulleted">
	<item><c>diffie-hellman-group1-sha1</c></item>
	<item><c>diffie-hellman-group-exchange-sha1</c></item>
	<item><c>diffie-hellman-group14-sha1</c></item>
      </list>
      <p>are not enabled by default as they now are regarded insecure,
      but are still supported and can be enabled with the options
      <seetype marker="ssh:ssh#preferred_algorithms_common_option">preferred_algorithms</seetype>
      or
      <seetype marker="ssh:ssh#modify_algorithms_common_option">modify_algorithms</seetype>.
      </p>
      </item>
      
      <item><url href="https://tools.ietf.org/html/rfc8332">RFC 8332</url>, Use of RSA Keys with SHA-256 and SHA-512 in the Secure Shell (SSH) Protocol.
      <p/>
      </item>
      
      <item><marker id="supported-ext-info"/>
      <url href="https://tools.ietf.org/html/rfc8308">RFC 8308</url>,
      Extension Negotiation in the Secure Shell (SSH) Protocol.
      <p>Implemented are:</p>
      <list type="bulleted">
	<item>The Extension Negotiation Mechanism</item>
	<item>The extension <c>server-sig-algs</c></item>
      </list>
      <p/>
      </item>

      <item>
	<url href="https://tools.ietf.org/html/rfc8731">Secure Shell (SSH) Key Exchange Method Using Curve25519 and Curve448</url>
	<p/>
      </item>

      <item>
	<url href="https://tools.ietf.org/html/rfc8709">RFC 8709</url>
	Ed25519 and Ed448 public key algorithms for the Secure Shell (SSH) protocol
      </item>

    </list>

  </section>

  <section>
    <title>SEE ALSO</title>
    <p><seeerl marker="kernel:application">application(3)</seeerl></p>
  </section>

</appref>
