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
- CLI
- Python
- JavaScript
# Add from default key
instavm ssh-key add
# Or specify the key directly
instavm ssh-key add "ssh-rsa AAAA... user@host"
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')}")
import { InstaVM } from 'instavm';
const client = new InstaVM('your_api_key');
const result = await client.ssh.addKey({
public_key: 'ssh-rsa AAAA... user@host',
});
console.log(result);
List SSH keys
- CLI
- Python
- JavaScript
instavm ssh-key list
keys = client.ssh.list_keys()
for key in keys:
print(f"{key.get('key_id')}: {key.get('fingerprint')}")
import { InstaVM } from 'instavm';
const client = new InstaVM('your_api_key');
const keys = await client.ssh.listKeys();
for (const key of keys) {
console.log(`${key.id}: ${key.name}`);
}
Delete an SSH key
- CLI
- Python
- JavaScript
instavm ssh-key remove 123
client.ssh.delete_key(key_id=123)
import { InstaVM } from 'instavm';
const client = new InstaVM('your_api_key');
await client.ssh.deleteKey(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:
- CLI
- Python
- JavaScript
instavm create
instavm connect <vm_id>
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}")
import { InstaVM } from 'instavm';
const client = new InstaVM('your_api_key');
const vm = await client.vms.create({}, true);
console.log(`ssh ${vm.ssh_user}@${vm.ssh_host} -p ${vm.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
.pubfile.
Error handling
- CLI
- Python
- JavaScript
# CLI exits with non-zero status and prints errors to stderr
instavm ssh-key add "invalid-key-format"
# Error: Invalid SSH public key format
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}")
import { InstaVM, InstaVMError } from 'instavm';
const client = new InstaVM('your_api_key');
try {
await client.ssh.addKey({ public_key: 'invalid' });
} catch (error) {
if (error instanceof InstaVMError) {
console.error(`SSH key error: ${error.message}`);
}
}
Next steps
- REST API: SSH Keys -- API endpoints
- Python SDK: Egress & Networking -- SSH key management in the SDK