---
title: "alpacon websh"
description: "Open an interactive Websh terminal or run a remote command with Alpacon CLI. Select an account, attach a work session, and place flags before the server name."
---

> Full documentation index: https://docs.alpacax.com/llms.txt

# alpacon websh

Open a Websh terminal or run a command on a server.

## Usage

`alpacon websh [flags] [USER@]SERVER [COMMAND...]`

`alpacon websh [command]`

## Key facts

- Place all flags before the server name; everything after it is passed to the remote command.
- Use `USER@SERVER` or `--username` to select an account.
- Browser login requires an active work session with the appropriate scope.
- Run subcommands as `alpacon websh [command]`.

## Flags

### Account and environment

| Flag | Type | Description |
| --- | --- | --- |
| `-u, --username` | `string` | Specify the username for command execution. |
| `-g, --groupname` | `string` | Specify the group name for command execution. |
| `--env` | `strings` | Repeat with `KEY` to read a value from the local shell. `KEY=VALUE` sets a literal value but exposes it in command history and process listings; never pass credentials this way. |

### Session

| Flag | Type | Description | Default |
| --- | --- | --- | --- |
| `--work-session` | `string` | Attach to this work session UUID, overriding the active session set by `alpacon work-session use`. | — |
| `-s, --share` | `bool` | Share the terminal via a temporary link. | `false` |
| `--read-only` | `bool` | Set shared session to read-only (default: false). | `false` |

### Output and help

| Flag | Type | Description | Default |
| --- | --- | --- | --- |
| `--output` | `string` | Output format: `table` or `json`. Inherited by all commands. | `table` |
| `-h, --help` | `bool` | Show command help. | `false` |

## Examples

Open a websh terminal for a server

```bash
alpacon websh my-server
```

Open as root user

```bash
alpacon websh root@my-server
```

Open with specific user and group

```bash
alpacon websh admin@my-server
alpacon websh -u admin -g developers my-server
```

Execute a command directly on a server

```bash
alpacon websh my-server "ls -la /var/log"
```

Run a command as a specific user

```bash
alpacon websh root@my-server "systemctl status nginx"
alpacon websh -u admin -g developers my-server "docker ps"
```

Set environment variables for the command

```bash
alpacon websh --env="KEY1=VALUE1" --env="KEY2=VALUE2" my-server 'echo $KEY1'
```

Use current shell's environment variable

```bash
alpacon websh --env="HOME" my-server 'echo $HOME'
```

Share the current terminal

```bash
alpacon websh --share my-server
alpacon websh --share --read-only=true my-server
```

Join an existing shared session

```bash
alpacon websh join --url "https://myws.us1.alpacon.io/websh/shared/abcd1234?channel=default" --password my-session-pass
```

Attach to a work session

```bash
alpacon websh --work-session 11111111-2222-3333-4444-555555555555 my-server
```

On Windows servers, the shell is PowerShell and commands run as SYSTEM regardless of `--username` or `--groupname`. See [Windows servers](/reference/platforms/windows/).

## Work session requirement

When you sign in with browser login, `alpacon websh` requires an active [work session](/reference/cli/work-session/). An interactive terminal needs the `websh` scope; executing a command directly (`alpacon websh my-server "command"`) needs the `command` scope. Token authentication (API token or service token) bypasses this requirement for `alpacon websh my-server "command"`, but a token cannot open an interactive terminal or use `watch`, `join`, or `invite`. Those need `alpacon login` without `-t`.

New personal API tokens cannot hold command-execution or file-transfer scopes. Existing tokens with those scopes keep working without a work session. Use a [service token](/use/iam/applications/service-tokens/) for automation and CI.

The session to attach is resolved from the `--work-session` flag, the `ALPACON_WORK_SESSION` environment variable, or the active session set with [`alpacon work-session use`](/reference/cli/work-session/use/)—in that order. When the gate denies the operation, `websh` exits with code **3**; run with `--output json` to get a machine-readable diagnostic on stderr. See [Gate errors](/reference/cli/work-session/#gate-errors) for the error codes.

## MFA authentication

When connecting as a system account (e.g., `root@my-server`), your workspace's [Authentication](/use/policies/authentication/) settings may require additional MFA verification.

In the CLI, the MFA flow works as follows:

1. The CLI displays an MFA authentication link
2. Open the link in your browser and complete MFA verification
3. The CLI automatically detects successful authentication and continues the operation

The MFA link expires after **3 minutes**. If the link expires, retry the command to receive a new link.

```
$ alpacon websh root@my-server
MFA authentication required.
Please open the following URL in your browser to complete MFA authentication:

  https://app.alpacon.io/mfa/verify?token=abc123

Waiting for MFA authentication... (timeout: 3m0s)
MFA authentication successful.
```

MFA verification remains valid for the duration configured in [workspace authentication settings](/use/policies/authentication/); it is not adjustable per member. Subsequent system account connections within this period will not require re-authentication.

MFA verification applies only to the CLI that requested it. Signing in separately in a browser or another machine’s CLI does not verify this CLI.

## API token ACLs

Running a command with a token (`alpacon websh my-server "command"`) is the same as `alpacon exec`. The token needs a server ACL entry allowing the server and an allowed-command entry for the command. A token cannot open an interactive Websh terminal.

For automation, use a [service token](/use/iam/applications/service-tokens/). On Alpacon Cloud, manage its **Pre-approved commands**; on a self-hosted install, its **Allowed commands**.

## Related commands

  
    Display a list of active websh sessions
  
  
    Show detailed information about a session
  
  
    Watch a session in read-only mode (staff/superuser only)
  
  
    Retrieve or search masked terminal records within a session (paid plans only)
  
  
    Invite users to a session by email
  
  
    Close an active session
  
  
    Force close a session (Superuser only)
  
  
    Join a shared session using a URL and password

Source: https://docs.alpacax.com/reference/cli/websh/
