def setup_ssh_key(hostname, user, password, port=22):
 logging.debug(('Performing SSH key setup on %s:%d as %s.' % (hostname, port, user)))
 try:
  public_key = get_public_key()
  session = remote.remote_login(client='ssh', host=hostname, port=port, username=user, password=password, prompt='[$#%]')
  session.cmd_output('mkdir -p ~/.ssh')
  session.cmd_output('chmod 700 ~/.ssh')
  session.cmd_output(("echo '%s' >> ~/.ssh/authorized_keys; " % public_key))
  session.cmd_output('chmod 600 ~/.ssh/authorized_keys')
  logging.debug('SSH key setup complete.')
 except Exception as err:
  logging.debug('SSH key setup has failed: %s', err)
  try:
   session.close()
  except:
   pass

def setup_ssh_key ( hostname , user , password , port = 22 ) : logging . debug ( ( 'Performing SSH key setup on %s:%d as %s.' % ( hostname , port , user ) ) ) try : public_key = get_public_key ( ) session = remote . remote_login ( client = 'ssh' , host = hostname , port = port , username = user , password = password , prompt = '[$#%]' ) session . cmd_output ( 'mkdir -p ~/.ssh' ) session . cmd_output ( 'chmod 700 ~/.ssh' ) session . cmd_output ( ( "echo '%s' >> ~/.ssh/authorized_keys; " % public_key ) ) session . cmd_output ( 'chmod 600 ~/.ssh/authorized_keys' ) logging . debug ( 'SSH key setup complete.' ) except Exception as err : logging . debug ( 'SSH key setup has failed: %s' , err ) try : session . close ( ) except : pass
setup up remote login in another server by using public key .