Skip to main content

SSH Access

SSH keys let you connect directly to InstaVM VMs from your terminal. Add your public key once and SSH into any VM on your account.

Add an SSH key

from instavm import InstaVM

client = InstaVM('your_api_key')

result = client.ssh.add_key(
public_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC..."
)

print(f"Key ID: {result.get('key_id')}")
print(f"Fingerprint: {result.get('fingerprint')}")

List SSH keys

keys = client.ssh.list_keys()

for key in keys:
print(f"{key.get('key_id')}: {key.get('fingerprint')}")

Delete an SSH key

client.ssh.delete_key(key_id=123)

Generate an SSH key pair

If you do not have a key pair:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
cat ~/.ssh/id_rsa.pub

Connect to a VM

Create a VM and use the returned SSH connection details:

client = InstaVM('your_api_key')
vm = client.vms.create(wait=True)

ssh_host = vm.get('ssh_host')
ssh_user = vm.get('ssh_user')
ssh_port = vm.get('ssh_port', 22)

print(f"ssh {ssh_user}@{ssh_host} -p {ssh_port}")

Then from your terminal:

ssh -i ~/.ssh/id_rsa user@vm-host.example.com -p 22

Key management notes

  • Keys are bound to your account, not individual VMs.
  • All keys on your account work across all your VMs.
  • Delete unused keys regularly.
  • Never share private keys. Only upload the .pub file.

Error handling

from instavm import InstaVM, InstaVMError

client = InstaVM('your_api_key')

try:
client.ssh.add_key(public_key="invalid_key")
except InstaVMError as e:
print(f"Failed: {e}")

Next steps