def remove_sshkey(host, known_hosts=None):
 if (known_hosts is None):
  if ('HOME' in os.environ):
   known_hosts = '{0}/.ssh/known_hosts'.format(os.environ['HOME'])
  else:
   try:
    known_hosts = '{0}/.ssh/known_hosts'.format(pwd.getpwuid(os.getuid()).pwd_dir)
   except Exception:
    pass
 if (known_hosts is not None):
  log.debug('Removing ssh key for {0} from known hosts file {1}'.format(host, known_hosts))
 else:
  log.debug('Removing ssh key for {0} from known hosts file'.format(host))
 cmd = 'ssh-keygen -R {0}'.format(host)
 subprocess.call(cmd, shell=True)

def remove_sshkey ( host , known_hosts = None ) : if ( known_hosts is None ) : if ( 'HOME' in os . environ ) : known_hosts = '{0}/.ssh/known_hosts' . format ( os . environ [ 'HOME' ] ) else : try : known_hosts = '{0}/.ssh/known_hosts' . format ( pwd . getpwuid ( os . getuid ( ) ) . pwd_dir ) except Exception : pass if ( known_hosts is not None ) : log . debug ( 'Removing ssh key for {0} from known hosts file {1}' . format ( host , known_hosts ) ) else : log . debug ( 'Removing ssh key for {0} from known hosts file' . format ( host ) ) cmd = 'ssh-keygen -R {0}' . format ( host ) subprocess . call ( cmd , shell = True )
remove a host from the known_hosts file .