def read_authorized_keys(filename=None, logger=None):
    """
    Return dictionary of public keys, indexed by user, read from `filename`.
    The file must be in ssh format, and only RSA keys are processed.
    If the file is not private, then no keys are returned.

    filename: string
        File to read from. The default is ``~/.ssh/authorized_keys``.

    logger: :class:`logging.Logger`
        Used for log messages.
    """
    if not filename:
        filename = \
            os.path.expanduser(os.path.join('~', '.ssh', 'authorized_keys'))

    logger = logger or NullLogger()

    if not os.path.exists(filename):
        raise RuntimeError('%r does not exist' % filename)

    if not is_private(filename):
        if sys.platform != 'win32' or HAVE_PYWIN32:
            raise RuntimeError('%r is not private' % filename)
        else:  #pragma no cover
            logger.warning('Allowed users file %r is not private', filename)

    errors = 0
    keys = {}
    with open(filename, 'r') as inp:
        for line in inp:
            line = line.rstrip()
            sharp = line.find('#')
            if sharp >= 0:
                line = line[:sharp]
            if not line:
                continue

            key_type, blank, rest = line.partition(' ')
            if key_type != 'ssh-rsa':
                logger.error('unsupported key type: %r', key_type)
                errors += 1
                continue

            key_data, blank, user_host = rest.partition(' ')
            if not key_data:
                logger.error('bad line (missing key data):')
                logger.error(line)
                errors += 1
                continue

            try:
                user, host = user_host.split('@')
            except __HOLE__:
                logger.error('bad line (require user@host):')
                logger.error(line)
                errors += 1
                continue

            logger.debug('user %r, host %r', user, host)
            try:
                ip_addr = socket.gethostbyname(host)
            except socket.gaierror:
                logger.warning('unknown host %r', host)
                logger.warning(line)

            data = base64.b64decode(key_data)
            start = 0
            name_len = _longint(data, start, 4)
            start += 4
            name = data[start:start+name_len]
            if name != 'ssh-rsa':
                logger.error('name error: %r vs. ssh-rsa', name)
                logger.error(line)
                errors += 1
                continue

            start += name_len
            e_len = _longint(data, start, 4)
            start += 4
            e = _longint(data, start, e_len)
            start += e_len
            n_len = _longint(data, start, 4)
            start += 4
            n = _longint(data, start, n_len)
            start += n_len
            if start != len(data):
                logger.error('length error: %d vs. %d', start, len(data))
                logger.error(line)
                errors += 1
                continue

            try:
                pubkey = RSA.construct((n, e))
            except Exception as exc:
                logger.error('key construct error: %r', exc)
                errors += 1
            else:
                keys[user_host] = pubkey

    if errors:
        raise RuntimeError('%d errors in %r, check log for details'
                           % (errors, filename))
    return keys
dataset/ETHPy150Open OpenMDAO/OpenMDAO-Framework/openmdao.util/src/openmdao/util/publickey.py/read_authorized_keys