Show a user's SSH public key from their LDAP entry.
12786
def show(config, username):  # pragma: no cover
        """"""
        client = Client()
        client.prepare_connection()
        key_api = API(client)
        for key, value in key_api.get_keys_from_ldap(username).items():
            print(value)
1177430
def Get(self,key):
		""""""

		for public_ip in self.public_ips:
			if public_ip.id == key:  return(public_ip)
			elif key == public_ip.internal:  return(public_ip)
564718
def ssh_get_info(node):
    """"""
    ssh_key = ""
    if node.cloud == "aws":
        raw_key = node.extra['key_name']
        ssh_key = "-i {0}{1}.pem ".format(CONFIG_DIR, raw_key)
        ssh_user = ssh_calc_aws(node)
    elif node.cloud == "azure":
        ssh_user = node.extra['properties']['osProfile']['adminUsername']
    elif node.cloud == "gcp":
        items = node.extra['metadata'].get('items', [{}])
        keyname = items['key' == 'ssh-keys'].get('value', "")
        pos = keyname.find(":")
        ssh_user = keyname[0:pos]
    elif node.cloud == "alicloud":
        ssh_user = ""
    return ssh_user, ssh_key
42260
def ssh(cls, vm_id, login, identity, args=None):
        """"""
        cmd = ['ssh']
        if identity:
            cmd.extend(('-i', identity,))

        version, ip_addr = cls.vm_ip(vm_id)
        if version == 6:
            cmd.append('-6')

        if not ip_addr:
            cls.echo('No IP address found for vm %s, aborting.' % vm_id)
            return

        cmd.append('%s@%s' % (login, ip_addr,))

        if args:
            cmd.extend(args)

        cls.echo('Requesting access using: %s ...' % ' '.join(cmd))
        return cls.execute(cmd, False)
1167132
def pubkey(self, identity, ecdh=False):
        """"""
        _verify_support(identity, ecdh)
        return trezor.Trezor.pubkey(self, identity=identity, ecdh=ecdh)
1206270
def get_ssh_client(ip,
                   ssh_private_key_file,
                   ssh_user='root',
                   port=22,
                   timeout=600,
                   wait_period=10):
    """"""
    if ip in CLIENT_CACHE:
        return CLIENT_CACHE[ip]

    start = time.time()
    end = start + timeout

    client = None
    while time.time() < end:
        try:
            client = establish_ssh_connection(
                ip,
                ssh_private_key_file,
                ssh_user,
                port,
                timeout=wait_period
            )
            execute_ssh_command(client, 'ls')
        except:  # noqa: E722
            if client:
                client.close()
            wait_period += wait_period
        else:
            CLIENT_CACHE[ip] = client
            return client

    raise IpaSSHException(
        'Attempt to establish SSH connection failed.'
    )
942117
def _get_user_data(self):
        
        key = ipa_utils.generate_public_ssh_key(
            self.ssh_private_key_file
        ).decode()
        script = BASH_SSH_SCRIPT.format(user=self.ssh_user, key=key)
        return script
170066
def _get_authentication_from_public_key_id(self, key_id):
        """"""
        for authentication in self._authentications:
            if authentication.is_key_id(key_id):
                return authentication
        return None
1207373
def _github_ssh_key_exists(cls):
        """"""
        remote_keys = map(lambda k: k._key, cls._user.get_keys())
        found = False
        pubkey_files = glob.glob(os.path.expanduser('~/.ssh/*.pub'))
        for rk in remote_keys:
            for pkf in pubkey_files:
                local_key = io.open(pkf, encoding='utf-8').read()
                # in PyGithub 1.23.0, remote key is an object, not string
                rkval = rk if isinstance(rk, six.string_types) else rk.value
                # don't use "==" because we have comments etc added in public_key
                if rkval in local_key:
                    found = True
                    break
        return found
908225
def generate_public_ssh_key(ssh_private_key_file):
    """"""
    try:
        with open(ssh_private_key_file, "rb") as key_file:
            key = key_file.read()
    except FileNotFoundError:
        raise IpaUtilsException(
            'SSH private key file: %s cannot be found.' % ssh_private_key_file
        )

    try:
        private_key = serialization.load_pem_private_key(
            key,
            password=None,
            backend=default_backend()
        )
    except ValueError:
        raise IpaUtilsException(
            'SSH private key file: %s is not a valid key file.'
            % ssh_private_key_file
        )

    return private_key.public_key().public_bytes(
        serialization.Encoding.OpenSSH,
        serialization.PublicFormat.OpenSSH
    )
1060096
def PrivateToPublicOpenSSH(key, host):
  
  # Create public key from private key.
  ssh_rsa = '00000007' + base64.b16encode('ssh-rsa')
  # Exponent.
  exponent = '%x' % (key.e,)
  if len(exponent) % 2:
      exponent = '0' + exponent
  ssh_rsa += '%08x' % (len(exponent) / 2,)
  ssh_rsa += exponent
  modulus = '%x' % (key.n,)
  if len(modulus) % 2:
      modulus = '0' + modulus
  if modulus[0] in '89abcdef':
      modulus = '00' + modulus
  ssh_rsa += '%08x' % (len(modulus) / 2,)
  ssh_rsa += modulus
  hash_string = base64.b64encode(base64.b16decode(ssh_rsa.upper()))
  public_key = 'ssh-rsa %s %s' % (hash_string, host)
  return public_key
667623
def _parse_uri_ssh(unt):
    """"""
    if '@' in unt.netloc:
        user, host_port = unt.netloc.split('@', 1)
    else:
        user, host_port = None, unt.netloc

    if ':' in host_port:
        host, port = host_port.split(':', 1)
    else:
        host, port = host_port, None

    if not user:
        user = None
    if not port:
        port = smart_open_ssh.DEFAULT_PORT
    else:
        port = int(port)

    return Uri(scheme=unt.scheme, uri_path=unt.path, user=user, host=host, port=port)
457154
def find_ssh_pub_key(self, name):
        
        return bool(self.nova.keypairs.findall(name=name))
1066568
def import_public_key(line):
    """"""
    log.debug('loading SSH public key: %r', line)
    file_type, base64blob, name = line.split()
    blob = base64.b64decode(base64blob)
    result = parse_pubkey(blob)
    result['name'] = name.encode('utf-8')
    assert result['type'] == file_type.encode('ascii')
    log.debug('loaded %s public key: %s', file_type, result['fingerprint'])
    return result
1266158
def ssh_session(key_filename,
                username,
                ip_address,
                *cli):
    
    local('ssh -t -i %s %s@%s %s' % (key_filename,
                                     username,
                                     ip_address,
                                     "".join(chain.from_iterable(cli))))
988193
def show(config, username):
        """"""
        client = Client()
        client.prepare_connection()
        user_api = API(client)
        CLI.show_user(user_api.show(username))
960387
def ssh_authorized_peers(peer_interface, user, group=None,
                         ensure_local_user=False):
    
    if ensure_local_user:
        ensure_user(user, group)
    priv_key, pub_key = get_keypair(user)
    hook = hook_name()
    if hook == '%s-relation-joined' % peer_interface:
        relation_set(ssh_pub_key=pub_key)
    elif hook == '%s-relation-changed' % peer_interface or \
            hook == '%s-relation-departed' % peer_interface:
        hosts = []
        keys = []

        for r_id in relation_ids(peer_interface):
            for unit in related_units(r_id):
                ssh_pub_key = relation_get('ssh_pub_key',
                                           rid=r_id,
                                           unit=unit)
                priv_addr = relation_get('private-address',
                                         rid=r_id,
                                         unit=unit)
                if ssh_pub_key:
                    keys.append(ssh_pub_key)
                    hosts.append(priv_addr)
                else:
                    log('ssh_authorized_peers(): ssh_pub_key '
                        'missing for unit %s, skipping.' % unit)
        write_authorized_keys(user, keys)
        write_known_hosts(user, hosts)
        authed_hosts = ':'.join(hosts)
        relation_set(ssh_authorized_hosts=authed_hosts)