# Your own server (SSH)

You connect an existing Linux server to MainPath over SSH, and MainPath then sets it up and uses it for deployments.

> Source: https://www.mainpath.ai/en/docs/own-server/

If you already have a Linux server, you store an SSH login in MainPath, and from then on MainPath takes care of the setup and the deployments; it does not matter which provider the server runs with.

## What the server needs to provide

The server must be reachable over SSH and have a user MainPath can work with, for example `deploy` or `root`. If it sits behind a firewall or NAT, connect it through a [network tunnel]({{< relref "network-tunnels" >}}); the host may then be an internal address. For authentication we recommend an SSH key pair instead of a password; if you do not have one yet, follow the instructions under [Create an SSH key]({{< relref "create-ssh-key" >}}).

## Registering the server in MainPath

1. Open **Servers** in the sidebar, click **Add server**, and choose **SSH**.
2. Enter the server's IP address or hostname under **Host**.
3. Leave **Port** at `22` unless your server offers SSH on a different port.
4. Enter the prepared user under **User**.
5. Under **Authentication**, choose **SSH key (recommended)** and paste the complete private key, including the `BEGIN` and `END` lines. Alternatively, you can store a password.
6. Optionally enable **Monitor server**, **Configure firewall**, and **Access via tunnel**. The firewall limits SSH to selected addresses; details are under [Servers]({{< relref "servers" >}}#monitoring-and-firewall). Behind a firewall or NAT, choose the [network tunnel]({{< relref "network-tunnels" >}}).
7. Save. The server is available when creating and editing projects.

Your own key is only needed for the initial setup. During that setup MainPath generates a deploy key of its own, adds it to the `authorized_keys` of the user, and works with that key from then on.

## What happens on the first deployment

Once the server is assigned to a project and the first pipeline runs, MainPath sets it up with Ansible: it installs Docker and Traefik as the reverse proxy and then applies the project configuration with backend, browser app, homepage, and database, depending on what your project contains. How the pipeline rolls out dev and production afterwards is described under [Git workflow and deployment]({{< relref "git-workflow" >}}).

For requests to reach Traefik, the DNS records of your [domain]({{< relref "domain" >}}) must point to the server.

