Skip to main content

Enable SSH

from gravixlayer import GravixLayer
from pathlib import Path
import os

client = GravixLayer()
runtime = client.runtime.create(template="python-3.12-base-small")

ssh = client.runtime.enable_ssh(runtime.runtime_id)

print(ssh.enabled)      # True
print(ssh.username)     # e.g. "user"
print(ssh.port)         # e.g. 22
print(ssh.connect_cmd)  # Full ssh command

# Save the private key locally
if ssh.private_key:
    key_path = Path.home() / f".gravixlayer-{runtime.runtime_id}.pem"
    key_path.write_text(ssh.private_key, encoding="utf-8")
    os.chmod(key_path, 0o600)

client.runtime.kill(runtime.runtime_id)

Parameters

ParameterTypeRequiredDescription
runtime_idstringYesRuntime identifier
regenerate_keysbooleanNoRegenerate SSH keys (default False)

Response

FieldTypeDescription
runtime_idstringRuntime identifier
enabledbooleanSSH enabled status
portintegerSSH port
usernamestringSSH username
connect_cmdstringFull SSH command
private_keystringPEM-encoded private key
public_keystringPublic key
ssh_configstringSSH config block
messagestringStatus message
Store private keys securely and set file permissions to 600.

Disable SSH

from gravixlayer import GravixLayer

client = GravixLayer()
runtime = client.runtime.create(template="python-3.12-base-small")

client.runtime.enable_ssh(runtime.runtime_id)

# Check status
status = client.runtime.ssh_status(runtime.runtime_id)
print(status.enabled)  # True

# Disable SSH
client.runtime.disable_ssh(runtime.runtime_id)

# Verify
status = client.runtime.ssh_status(runtime.runtime_id)
print(status.enabled)  # False

client.runtime.kill(runtime.runtime_id)

Parameters

ParameterTypeRequiredDescription
runtime_idstringYesRuntime identifier
Disable SSH as soon as interactive access is no longer needed.

Key Rotation

Rotate keys when credentials may have been exposed, or as part of regular security policy.
from gravixlayer import GravixLayer
from pathlib import Path
import os

client = GravixLayer()
runtime = client.runtime.create(template="python-3.12-base-small")

# Enable SSH
initial = client.runtime.enable_ssh(runtime.runtime_id)
print("Initial connect:", initial.connect_cmd)

# Rotate keys
rotated = client.runtime.enable_ssh(runtime.runtime_id, regenerate_keys=True)
print("New connect:", rotated.connect_cmd)

# Save the new private key
if rotated.private_key:
    key_path = Path.home() / f".gravixlayer-{runtime.runtime_id}.pem"
    key_path.write_text(rotated.private_key, encoding="utf-8")
    os.chmod(key_path, 0o600)

client.runtime.kill(runtime.runtime_id)
  1. Call enable_ssh with regenerate_keys=True.
  2. Save the new private key securely (permissions 600).
  3. Remove old local key files.
  4. Verify access using the new connect_cmd.