# Linux servers

Enroll one Linux server in Teleport and connect to it from a beam over SSH.

Run the Teleport SSH Service on a Linux server to make it reachable from a beam. The service connects out to your Teleport cluster. Inside the beam, use `tsh ssh` with the beam's delegated identity. SSH does not use VNet.

<!-- illustration
id: beam-server-connectivity
style: docs-isometric
type: static
title: Linux server access from a beam
description: The Teleport agent on the Linux server dials out to the Beams cluster proxy. The beam uses tsh ssh to connect over that tunnel.

Group the Teleport agent and SSH Service inside the Linux server. Show a dashed outbound tunnel from the agent toward the Beams cluster proxy, and a solid arrow in the opposite direction for tsh ssh via the Teleport Proxy. The arrows indicate who initiates the tunnel and the SSH session, not two independent transports. Do not draw VNet, an inbound public port, or a direct connection from the beam to the server. Keep the directions legible on mobile.
-->

## Prerequisites

- A Teleport cluster v18.8.0 or later with Beams enabled. You need permission to create node join tokens, read their registration secrets, manage roles and create beams.
- A workstation with `tctl` and `tsh`, signed in to the cluster.
- A Linux server you administer, with systemd, an existing non-root login for the beam and outbound connectivity to the Teleport proxy. This example uses the login `beam-reader`. Use a non-privileged account without `sudo` and grant it only the OS permissions the task needs.

## Enroll the server

Use [Bound Keypair Joining](https://goteleport.com/docs/installation/agents/bound-keypair/) to enroll the SSH Service. The server uses a single-use registration secret on its first join. It generates its own keypair and stores the private key and join state in `/var/lib/teleport`. Keep that directory across restarts and don't copy it to another server. Create a separate token for each server.

### Create a registration secret

On your workstation, save the following as `server-join.yaml`. Replace `YYYY-MM-DDTHH:MM:SSZ` with a UTC timestamp shortly in the future. The deadline limits first registration without expiring the token used for recovery.

```yaml
kind: token
version: v2
metadata:
  name: example-server-join
spec:
  roles: [Node]
  join_method: bound_keypair
  bound_keypair:
    onboarding:
      must_register_before: "YYYY-MM-DDTHH:MM:SSZ"
    recovery:
      mode: standard
      limit: 1
```

**Admin workstation**

```sh
tctl create server-join.yaml
```

In a private terminal, run `tctl get token/example-server-join --with-secrets` and securely transfer only the `status.bound_keypair.registration_secret` value to `/root/teleport-node.registration-secret` on the server. Make the file readable only by root. Don't copy the secret into a client beam or commit it to source control.

### Configure and start the SSH Service

[Install Teleport on the Linux server](https://goteleport.com/docs/enroll-resources/server-access/getting-started/#step-14-install-teleport-on-your-linux-host) using the instructions for your cluster and Linux distribution. On a new server, save the following as `/etc/teleport.yaml`. Replace `teleport.example.com:443` with your Teleport proxy address.

```yaml
version: v3
teleport:
  nodename: example-server
  data_dir: /var/lib/teleport
  proxy_server: teleport.example.com:443
  join_params:
    token_name: example-server-join
    method: bound_keypair
    bound_keypair:
      registration_secret_path: /root/teleport-node.registration-secret
ssh_service:
  enabled: true
  labels:
    beams-access: example-server
auth_service:
  enabled: false
proxy_service:
  enabled: false
```

**Linux server**

```sh
sudo systemctl enable --now teleport
```

Check for `example-server` in the Teleport Web UI or run `tsh ls` from a workstation session that can view it. After it joins, remove `registration_secret_path` and its now-empty `bound_keypair` block from `join_params`, then delete the secret file and any transfer copies. Keep the named token, the `bound_keypair` join method, and the data directory. The initial join uses the one recovery attempt in this example; see the [Bound Keypair guide](https://goteleport.com/docs/installation/agents/bound-keypair/) if the server later needs to rejoin.

## Delegate one server and login

Save this role as `beam-server-access.yaml`. Use the existing non-root account you chose on the server in place of `beam-reader` if different. Apply the label only to the server you intend to expose to this role.

```yaml
kind: role
version: v8
metadata:
  name: beam-server-access
spec:
  allow:
    node_labels:
      beams-access: example-server
    logins: [beam-reader]
```

**Admin workstation**

```sh
tctl create beam-server-access.yaml
```

Assign `beam-server-access` to your Teleport user through your user or SSO role mapping, then sign in again. Your cluster must allow you to [delegate the role](/docs/identity/delegation/#control-which-roles-can-be-delegated).

## Connect from a beam

**Local terminal**

```sh
tsh beams add --roles=beam-server-access --no-share-connected-accounts
```

Inside the beam, list the servers you can access. Replace `example-server` with the name from `tsh ls` and `beam-reader` with the login you granted. The example runs `hostname` on the server to verify the connection.

**Inside the beam**

```sh
tsh ls
tsh ssh beam-reader@example-server hostname
```

When you're done, [delete the beam](/docs/identity/delegation/#3-end-access-when-the-task-is-done). To enroll more servers, see [Teleport Server Auto-Discovery](https://goteleport.com/docs/enroll-resources/auto-discovery/servers/).
