code: def generate_rsa_key_pair():
      
  
      key = rsa.generate_private_key(
          backend=default_backend(), public_exponent=65537, key_size=2048)
  
      public_key = key.public_key().public_bytes(
          serialization.Encoding.OpenSSH,
          serialization.PublicFormat.OpenSSH).decode("utf-8")
  
      pem = key.private_bytes(
          encoding=serialization.Encoding.PEM,
          format=serialization.PrivateFormat.TraditionalOpenSSL,
          encryption_algorithm=serialization.NoEncryption()).decode("utf-8")
  
      return public_key, pem
docs: Create public and private ssh-keys.