code: def generate_public_ssh_key(ssh_private_key_file):
      
      try:
          with open(ssh_private_key_file, "rb") as key_file:
              key = key_file.read()
      except FileNotFoundError:
          raise IpaUtilsException(
              'SSH private key file: %s cannot be found.' % ssh_private_key_file
          )
  
      try:
          private_key = serialization.load_pem_private_key(
              key,
              password=None,
              backend=default_backend()
          )
      except ValueError:
          raise IpaUtilsException(
              'SSH private key file: %s is not a valid key file.'
              % ssh_private_key_file
          )
  
      return private_key.public_key().public_bytes(
          serialization.Encoding.OpenSSH,
          serialization.PublicFormat.OpenSSH
      )
docs: Generate SSH public key from private key file.