<commit_before>.. toctree::
   :hidden:

   changes
   api

.. currentmodule:: asyncssh

.. include:: ../README.rst

.. _ClientExamples:

Client Examples
===============

Simple client
-------------

The following code shows an example of a simple SSH client which logs into
localhost and lists files in a directory named 'abc' under the user's home
directory. The username provided is the logged in user, and the user's
default SSH client keys or certificates are presented during authentication.
The server's host key is checked against the user's SSH known_hosts file and
the connection will fail if there's no entry for localhost there or if the
key doesn't match.

   .. include:: ../examples/simple_client.py
      :literal:
      :start-line: 15

To check against a different set of server host keys, they can be read
and provided in the server_host_keys argument when the :class:`SSHClient`
instance is created:

   .. code::

     host_keys = asyncssh.read_public_key_list('ssh_host_keys.pub')

     conn, client = yield from asyncssh.create_connection(None, 'localhost',
                                                          server_host_keys=host_keys)


Server host key checking can be disabled by setting the server_host_keys
argument to ``None``, but that's not recommended as it makes the
connection vulnerable to a man-in-the-middle attack.

To log in as a different remote user, the username argument can be
provided:

   .. code::

     conn, client = yield from asyncssh.create_connection(None, 'localhost',
                                                          username='user123')

To use a different set of client keys for authentication, they can be
read and provided in the client_keys argument:

   .. code::

     client_key = asyncssh.read_private_key('my_ssh_key')

     conn, client = yield from asyncssh.create_connection(None, 'localhost',
                                                          client_keys=[client_key])
<commit_msg>Fix an outdated reference in the documentation.<commit_after>.. toctree::
   :hidden:

   changes
   api

.. currentmodule:: asyncssh

.. include:: ../README.rst

.. _ClientExamples:

Client Examples
===============

Simple client
-------------

The following code shows an example of a simple SSH client which logs into
localhost and lists files in a directory named 'abc' under the user's home
directory. The username provided is the logged in user, and the user's
default SSH client keys or certificates are presented during authentication.
The server's host key is checked against the user's SSH known_hosts file and
the connection will fail if there's no entry for localhost there or if the
key doesn't match.

   .. include:: ../examples/simple_client.py
      :literal:
      :start-line: 15

To check against a different set of server host keys, they can be read
and provided in the known_hosts argument when the :class:`SSHClient`
instance is created:

   .. code::

     conn, client = yield from asyncssh.create_connection(None, 'localhost',
                                                          known_hosts='my_known_hosts')


Server host key checking can be disabled by setting the known_hosts
argument to ``None``, but that's not recommended as it makes the
connection vulnerable to a man-in-the-middle attack.

To log in as a different remote user, the username argument can be
provided:

   .. code::

     conn, client = yield from asyncssh.create_connection(None, 'localhost',
                                                          username='user123')

To use a different set of client keys for authentication, they can be
read and provided in the client_keys argument:

   .. code::

     client_key = asyncssh.read_private_key('my_ssh_key')

     conn, client = yield from asyncssh.create_connection(None, 'localhost',
                                                          client_keys=[client_key])

{'fraction_non_alphanumeric': 0.07942608250064054, 'fraction_numerical': 0.0025621316935690495, 'mean_word_length': 2.6726246472248354, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2303425', 'n_tokens_mistral': 1008, 'n_tokens_neox': 919, 'n_words': 432}