code: def remove_sshkey(host, known_hosts=None):
      '''
      Remove a host from the known_hosts file
      '''
      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 %s from known hosts file %s',
              host, known_hosts
          )
      else:
          log.debug('Removing ssh key for %s from known hosts file', host)
  
      cmd = 'ssh-keygen -R {0}'.format(host)
      subprocess.call(cmd, shell=Truef remove_sshkey(host, known_hosts=None):
      '''
      Remove a host from the known_hosts file
      '''
      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 %s from known hosts file %s',
              host, known_hosts
          )
      else:
          log.debug('Removing ssh key for %s from known hosts file', host)
  
      cmd = 'ssh-keygen -R {0}'.format(host)
      subprocess.call(cmd, shell=True)
docs: Remove a host from the known_hosts file