<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _get_connection(host, username: str, key_path: str) \ -> paramiko.Transport or None: """Return an authenticated SSH connection. :param host: host or IP of the machine :type host: str :param username: SSH username :type username: str :param key_path: path to the SSH private key for SSH auth :type key_path: str :return: SSH connection :rtype: paramiko.Transport or None """

    if not username:
        username = shakedown.cli.ssh_user
    if not key_path:
        key_path = shakedown.cli.ssh_key_file
    key = validate_key(key_path)
    transport = get_transport(host, username, key)

    if transport:
        transport = start_transport(transport, username, key)
        if transport.is_authenticated():
            return transport
        else:
            print("error: unable to authenticate {}@{} with key {}".format(username, host, key_path))
    else:
        print("error: unable to connect to {}".format(host))

    return None