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:
- Python
- TypeScript
- CLI
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}")
import { MorphCloudClient } from 'morphcloud';
const client = new MorphCloudClient();
async function getInstanceSshKey() {
const instance_id = "morphvm_abc123"; // Replace with your instance ID
// Get instance and retrieve SSH key
const instance = await client.instances.get({ instance_id: instance_id });
const sshKey = await instance.ssh_key();
console.log(`Public Key:\n${sshKey.publicKey}`);
console.log(`Private Key:\n${sshKey.privateKey}`);
}
getInstanceSshKey();
# Get SSH key for an instance
morphcloud instance ssh-key get morphvm_abc123
Rotate Instance SSH Key
Generate a new SSH key pair for enhanced security:
- Python
- TypeScript
- CLI
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!")
import { MorphCloudClient } from 'morphcloud';
const client = new MorphCloudClient();
async function rotateInstanceSshKey() {
const instance_id = "morphvm_abc123"; // Replace with your instance ID
// Get instance and rotate SSH key
const instance = await client.instances.get({ instance_id: instance_id });
const newSshKey = await instance.ssh_key_rotate();
console.log(`New Public Key:\n${newSshKey.publicKey}`);
console.log(`New Private Key:\n${newSshKey.privateKey}`);
console.log("SSH key rotated successfully!");
}
rotateInstanceSshKey();
# Rotate SSH key for an instance
morphcloud instance ssh-key rotate morphvm_abc123
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.