def add_host_keys(name, hostname):
 from fabtools.require.files import directory as _require_directory, file as _require_file
 ssh_dir = posixpath.join(home_directory(name), '.ssh')
 _require_directory(ssh_dir, mode='700', owner=name, use_sudo=True)
 known_hosts_filename = posixpath.join(ssh_dir, 'known_hosts')
 _require_file(known_hosts_filename, mode='644', owner=name, use_sudo=True)
 known_hosts = uncommented_lines(known_hosts_filename, use_sudo=True)
 with hide('running', 'stdout'):
  res = run(('ssh-keyscan -t rsa,dsa %s 2>/dev/null' % hostname))
 for host_key in res.splitlines():
  if (host_key not in known_hosts):
   sudo(('echo %s >>%s' % (quote(host_key), quote(known_hosts_filename))))

def add_host_keys ( name , hostname ) : from fabtools . require . files import directory as _require_directory , file as _require_file ssh_dir = posixpath . join ( home_directory ( name ) , '.ssh' ) _require_directory ( ssh_dir , mode = '700' , owner = name , use_sudo = True ) known_hosts_filename = posixpath . join ( ssh_dir , 'known_hosts' ) _require_file ( known_hosts_filename , mode = '644' , owner = name , use_sudo = True ) known_hosts = uncommented_lines ( known_hosts_filename , use_sudo = True ) with hide ( 'running' , 'stdout' ) : res = run ( ( 'ssh-keyscan -t rsa,dsa %s 2>/dev/null' % hostname ) ) for host_key in res . splitlines ( ) : if ( host_key not in known_hosts ) : sudo ( ( 'echo %s >>%s' % ( quote ( host_key ) , quote ( known_hosts_filename ) ) ) )
add all public keys of a host to the users ssh known hosts file .