# Authorize an SSH key

> Authorize your public key on the running machine and get the command to connect. You log in as its user, which has passwordless sudo. The address changes after a stop and resume: call this again then. Not available with test-mode keys.

`POST https://api.zavu.dev/v1/sandboxes/{sandboxId}/ssh`

Authorize your public key on the running machine and get the command to connect. You log in as its user, which has passwordless sudo. The address changes after a stop and resume: call this again then. Not available with test-mode keys.

## Parameters

- `sandboxId` (path, string, required): Sandbox ID.

## Body

- `publicKey` (string, required): An OpenSSH public key: the one line in your `.pub` file. A private key is refused with `400`.

## Responses

### 200

Authorized.

- `ssh` (object, required)
  - `host` (string, required): The machine's address. It changes after a stop and resume: authorize the key again then.
  - `user` (string, required)
  - `command` (string, required): Ready to paste.

### 400

Not an OpenSSH public key (a private key is refused), or a test-mode key.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 401

Unauthorized.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 404

Sandbox not found, or it belongs to another project.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 409

`sandbox_not_running`: the sandbox must be running for this. Resume it first.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

## Example

```bash
curl -X POST "https://api.zavu.dev/v1/sandboxes/sandbox_abc123/ssh" \
  -H "Authorization: Bearer $ZAVUDEV_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "publicKey": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGq user@laptop"
}'
```

```typescript
import Zavudev from "@zavudev/sdk";

const zavu = new Zavudev({ apiKey: process.env.ZAVUDEV_API_KEY });

const result = await zavu.sandboxes.ssh.authorize("sandbox_abc123", {
  publicKey: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGq user@laptop",
});

console.log(result);
```
