Install ssh key on server.
199124
protected function installSSHKeyOnServer()
    {
        $this->info('Adding SSH key to Laravel Forge server');
        // We cannot use ssh-copy-id -i ~/.ssh/id_rsa.pub forge@146.185.164.54 because SSH acces via user/password is not enabled on Laravel Forge
        // We need to use the Laravel Forge API to add a key

        $this->url = $this->endPointAPIURL();

        $response = $this->postKeyToLaravelForgeServer($keyName = $this->getUniqueKeyNameFromEmail());

        $result = json_decode($contents = $response->getBody()->getContents());

        if (! isset($result->status)) {
            $this->error("An error has been succeded: $contents");
            die();
        }
        if ($result->status == 'installed') {
            $this->info("The SSH Key ($keyName) has been correctly installed in Laravel Forge Server " . $this->server_name . ' (' . $this->server . ')');
        }
    }
1174425
def set_server(self, server_pos, key, value):
        """"""
        self.servers.set_server(server_pos, key, value)
452748
def ssh(ctx, cluster_id, key_file):
    """"""
    session = create_session(ctx.obj['AWS_PROFILE_NAME'])

    client = session.client('emr')
    result = client.describe_cluster(ClusterId=cluster_id)
    target_dns = result['Cluster']['MasterPublicDnsName']
    ssh_options = '-o StrictHostKeyChecking=no -o ServerAliveInterval=10'
    cmd = 'ssh {ssh_options}  -i {key_file} hadoop@{target_dns}'.format(
        ssh_options=ssh_options, key_file=key_file, target_dns=target_dns)
    subprocess.call(cmd, shell=True)
352214
def _start_server(self, *args):
        """"""

        self.log("Starting server", args)
        secure = self.certificate is not None
        if secure:
            self.log("Running SSL server with cert:", self.certificate)
        else:
            self.log("Running insecure server without SSL. Do not use without SSL proxy in production!", lvl=warn)

        try:
            self.server = Server(
                (self.host, self.port),
                secure=secure,
                certfile=self.certificate  # ,
                # inherit=True
            ).register(self)
        except PermissionError:
            self.log('Could not open (privileged?) port, check '
                     'permissions!', lvl=critical)
427650
def set_server(self, server_pos, key, value):
        """"""
        self._server_list[server_pos][key] = value
607754
def configure_ssh_command(ip, command)
      use_sudo = ChefWorkflow::KnifeSupport.use_sudo
      command = "#{use_sudo ? 'sudo ': ''}#{command}"

      options = { }

      options[:password] = ChefWorkflow::KnifeSupport.ssh_password          if ChefWorkflow::KnifeSupport.ssh_password
      options[:keys]     = [ChefWorkflow::KnifeSupport.ssh_identity_file]   if ChefWorkflow::KnifeSupport.ssh_identity_file

      Net::SSH.start(ip, ChefWorkflow::KnifeSupport.ssh_user, options) do |ssh|
        ssh.open_channel do |ch|
          ch.request_pty do |ch, success|
            if !success and use_sudo
              raise "The use_sudo setting requires a PTY, and your SSH is rejecting our attempt to get one."
            end
          end

          ch.on_open_failed do |ch, code, desc|
            raise "Connection Error to #{ip}: #{desc}"
          end

          ch.exec(command) do |ch, success|
            yield ch, success
          end
        end

        ssh.loop
      end
    end
255573
def ssh_key(key):
        
        value = str(key)
        # Ensure the file exists locally
        if not os.path.isfile(value):
            raise Exception("File Does not Exist: %s" % key)
        return value
94080
def setup(self):
        ''''''
        log.debug( 'New request from address %s, port %d',  self.client_address )
        
        try:
            self.transport.load_server_moduli()
        except:
            log.exception( '(Failed to load moduli -- gex will be unsupported.)' )
            raise
        try:
            self.transport.add_server_key(self.host_key)
        except:
            if self.host_key is None:
                log.critical('Host key not set!  SSHHandler MUST define the host_key parameter.')
                raise NotImplementedError('Host key not set!  SSHHandler instance must define the host_key parameter.  Try host_key = paramiko_ssh.getRsaKeyFile("server_rsa.key").')
        
        try:
            # Tell transport to use this object as a server
            log.debug( 'Starting SSH server-side negotiation' )
            self.transport.start_server(server=self)
        except SSHException, e:
           log.warn('SSH negotiation failed. %s', e)
           raise
        
        # Accept any requested channels
        while True:
            channel = self.transport.accept(20)
            if channel is None:
                # check to see if any thread is running
                any_running = False
                for c, thread in self.channels.items():
                    if thread.is_alive():
                        any_running = True
                        break
                if not any_running:
                    break
            else:
                log.info( 'Accepted channel %s', channel )
294226
def install(self):
        
        try:
            if self.args.server is not None:
                server = ServerLists(self.server_type)
                DynamicImporter(
                    'ezhost',
                    server.name,
                    args=self.args,
                    configure=self.configure
                )
            else:
                ServerCommand(self.args)
        except Exception as e:
            raise e
1323058
def install_key(self, keyfile, authorized_keys):
        """"""

        # Make the directory containing the authorized_keys
        # file, if it doesn't exist. (Typically ~/.ssh).
        # Ignore errors; we'll fail shortly if we can't
        # create the authkeys file.
        try:
            os.makedirs(os.path.dirname(authorized_keys), 0o700)
        except OSError:
            pass

        keydata = open(keyfile).read()
        target_fd = os.open(authorized_keys, os.O_RDWR | os.O_CREAT, 0o600)
        self.install_key_data(keydata, os.fdopen(target_fd, 'w+'))
264028
def create_ssh_pub_key(self, name, key):
        
        self.nova.keypairs.create(name, key)
392909
def _add_ssh_key(ret):
    '''
    
    '''
    priv = None
    if __opts__.get('ssh_use_home_key') and os.path.isfile(os.path.expanduser('~/.ssh/id_rsa')):
        priv = os.path.expanduser('~/.ssh/id_rsa')
    else:
        priv = __opts__.get(
            'ssh_priv',
            os.path.abspath(os.path.join(
                __opts__['pki_dir'],
                'ssh',
                'salt-ssh.rsa'
            ))
        )
    if priv and os.path.isfile(priv):
        ret['priv'] = priv
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
1007253
def create(cls, name, value):
        
        sshkey_params = {
            'name': name,
            'value': value,
        }

        result = cls.call('hosting.ssh.create', sshkey_params)
        return result
653580
def setup(addr, user, remote_path, local_key=None):
    """"""
    port = find_port(addr, user)

    if not port or not is_alive(addr, user):
        port = new_port()

        scp(addr, user, __file__, '~/unixpipe', local_key)

        ssh_call = ['ssh', '-fL%d:127.0.0.1:12042' % port,
                    '-o', 'ExitOnForwardFailure=yes',
                    '-o', 'ControlPath=~/.ssh/unixpipe_%%r@%%h_%d' % port,
                    '-o', 'ControlMaster=auto',
                    '%s@%s' % (user, addr,), 'python', '~/unixpipe',
                    'server', remote_path]
        if local_key:
            ssh_call.insert(1, local_key)
            ssh_call.insert(1, '-i')

        subprocess.call(ssh_call)
        # XXX Sleep is a bad way to wait for the tunnel endpoint
        time.sleep(1)

    return port
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)
15318
def connect_ssh(*args, **kwargs):
        

        client = SSHClient()
        client.connect(*args, **kwargs)
        return client