---
title: "alpacon-websh-action"
description: "Execute shell commands on remote servers in your CI/CD workflows. Supports running as specific users and groups, environment variables, and multi-line scripts."
---

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

# alpacon-websh-action

Execute shell commands on remote servers in your Alpacon workspace. Supports running commands as specific users and groups, passing environment variables, and multi-line scripts.

## Inputs

| Name | Description | Required | Default |
|------|-------------|----------|---------|
| `workspace-url` | Alpacon workspace URL | Yes | |
| `api-token` | Alpacon service token key (`alpst-`) | Yes | |
| `target` | Target server name | Yes | |
| `script` | Shell command or script to execute | Yes | |
| `username` | The application's server account to run the command as | No | |
| `groupname` | Group override (unavailable to service tokens; they use their account's private group) | No | |
| `env` | Environment variables (one per line, `KEY=VALUE` or `KEY` format) | No | |

## Usage

### Basic command execution

```yaml
- name: Deploy application
  uses: alpacax/alpacon-websh-action@v1
  with:
    workspace-url: ${{ secrets.ALPACON_WORKSPACE_URL }}
    api-token: ${{ secrets.ALPACON_SERVICE_TOKEN }}
    target: 'prod-server'
    username: 'ci-deploy'
    script: |
      cd /opt/myapp && git pull && npm install && pm2 restart app
```

### Execute as the application account

```yaml
- name: Copy files as the application account
  uses: alpacax/alpacon-websh-action@v1
  with:
    workspace-url: ${{ secrets.ALPACON_WORKSPACE_URL }}
    api-token: ${{ secrets.ALPACON_SERVICE_TOKEN }}
    target: 'web-server'
    username: 'ci-deploy'
    script: cp -r /tmp/build/. /home/ci-deploy/app/public/
```

### Pass environment variables

```yaml
- name: Run with environment variables
  uses: alpacax/alpacon-websh-action@v1
  with:
    workspace-url: ${{ secrets.ALPACON_WORKSPACE_URL }}
    api-token: ${{ secrets.ALPACON_SERVICE_TOKEN }}
    target: 'prod-server'
    username: 'ci-deploy'
    env: |
      APP_ENV=production
      DB_HOST=localhost
      LOG_LEVEL=info
    script: |
      echo "Deploying to $APP_ENV"
      sudo systemctl restart myapp
```

The `env` input supports two formats:
- `KEY=VALUE`: sets the variable to the specified value
- `KEY`: forwards the variable from the runner environment

## Notes

- Requires [`alpacon-setup-action`](/reference/actions/setup/) to run first
- Each line in `script` is executed as a separate command
- Keep dependent shell operations on one line, such as `cd /opt/myapp && git pull`
- Empty lines and comment-only lines (starting with `#`) are skipped
- A service token cannot override its account's private group with `groupname`
- The system-service example needs the [sudo settings and command rule](/integrate/github-actions/#restart-services-with-sudo)

## See also

- [Actions reference overview](/reference/actions/)
- [alpacon-setup-action](/reference/actions/setup/)
- [alpacon-cp-action](/reference/actions/cp/)
- [alpacon-common-action](/reference/actions/common/)

## Resources

- [GitHub Marketplace](https://github.com/marketplace/actions/alpacon-websh-action)
- [Source code](https://github.com/alpacax/alpacon-websh-action)
- [CLI reference: alpacon websh](/reference/cli/websh/)

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