Skip to main content

SSH Key Management

SSH keys provide secure access to your instances. Morph Cloud supports both user-level SSH keys (shared across instances) and instance-specific SSH keys for enhanced security.

Get Instance SSH Key

Retrieve the SSH key for a specific instance:

from morphcloud.api import MorphCloudClient

client = MorphCloudClient()

instance_id = "morphvm_abc123" # Replace with your instance ID

# Get instance and retrieve SSH key
instance = client.instances.get(instance_id)
ssh_key = instance.ssh_key()

print(f"Public Key:\n{ssh_key.public_key}")
print(f"Private Key:\n{ssh_key.private_key}")

Rotate Instance SSH Key

Generate a new SSH key pair for enhanced security:

from morphcloud.api import MorphCloudClient

client = MorphCloudClient()

instance_id = "morphvm_abc123" # Replace with your instance ID

# Get instance and rotate SSH key
instance = client.instances.get(instance_id)
new_ssh_key = instance.ssh_key_rotate()

print(f"New Public Key:\n{new_ssh_key.public_key}")
print(f"New Private Key:\n{new_ssh_key.private_key}")
print("SSH key rotated successfully!")

Best Practices

  • Save private keys securely with appropriate file permissions (600)
  • Rotate keys regularly for enhanced security
  • Use instance-specific keys for production environments
  • Keep private keys confidential and never share them

SSH key management ensures secure access to your Morph Cloud instances while maintaining flexibility and security.