def add_ssh_public_keys(name, filenames):
 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)
 authorized_keys_filename = posixpath.join(ssh_dir, 'authorized_keys')
 _require_file(authorized_keys_filename, mode='600', owner=name, use_sudo=True)
 for filename in filenames:
  with open(filename) as public_key_file:
   public_keys = public_key_file.read().strip().split('\n')
  for public_key in public_keys:
   if (public_key not in authorized_keys(name)):
    sudo(('echo %s >>%s' % (quote(public_key), quote(authorized_keys_filename))))

def add_ssh_public_keys ( name , filenames ) : 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 ) authorized_keys_filename = posixpath . join ( ssh_dir , 'authorized_keys' ) _require_file ( authorized_keys_filename , mode = '600' , owner = name , use_sudo = True ) for filename in filenames : with open ( filename ) as public_key_file : public_keys = public_key_file . read ( ) . strip ( ) . split ( '\n' ) for public_key in public_keys : if ( public_key not in authorized_keys ( name ) ) : sudo ( ( 'echo %s >>%s' % ( quote ( public_key ) , quote ( authorized_keys_filename ) ) ) )
add multiple public keys to the users authorized ssh keys .