# How to set up pair programming using tmux

## Introduction <a href="#introduction" id="introduction"></a>

Command-line interface (CLI) text editors, such as [Vim](https://www.vim.org/), are widely used by developers. CLI development environments can offer many advantages over their counterparts, such as the ease of initial configuration, the ability to interact with other CLI utilities, and the convenience of working with remote servers. All of these factors can contribute to a large improvement in productivity.

A popular open-source terminal multiplexer [tmux](https://en.wikipedia.org/wiki/Tmux) is often used for CLI work. This tool can be beneficial on servers and devices that have only a single terminal interface. You can create several sessions for different workflows, for example:

* Interacting with Docker container shells
* Pair programming
* Continuous file transfers

By incorporating [Meshnet](https://nordvpn.com/meshnet/), devices from different networks can be connected to a single, secure virtual network. With this configuration, the developers' devices can be easily reached using remote access methods, such as [secure shell](https://en.wikipedia.org/wiki/Secure_Shell) (SSH). As a result, a shared tmux session between remote devices can be established.

This article contains instructions on how to set up tmux on macOS and Linux devices and initiate a shared terminal session using Meshnet.

## Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

To use tmux for pair programming, your system must allow SSH connections from other devices in your Meshnet. See the [Enable SSH access](/how-to/remote-access/access-remote-systems-over-ssh.md#enable-ssh-access) section of the "How to access remote systems over Meshnet using SSH" article for instructions on how to enable SSH on your devices.

## Installing tmux <a href="#installing-tmux" id="installing-tmux"></a>

{% tabs %}
{% tab title="Linux" %}
You can install tmux on Linux by running the following command in the terminal:

{% code overflow="wrap" %}

```bash
sudo apt install tmux -y
```

{% endcode %}
{% endtab %}

{% tab title="macOS" %}
To install tmux on macOS, you need to use the [Homebrew](https://brew.sh/) package manager.

1. Open **Terminal**.
2. Enter the following command:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
   </code></pre>

   &#x20;

   For additional information about the installation process, refer to [Homebrew documentation](https://docs.brew.sh/Installation).
3. Follow the on-screen instructions to finish the installation.
4. install tmux by running the following command:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">brew install tmux
   </code></pre>

{% endtab %}
{% endtabs %}

## Connecting via SSH <a href="#connecting-via-ssh" id="connecting-via-ssh"></a>

To participate in the shared session, you have to access the host device from your client device via SSH.

1. Open **Command Prompt** (on Windows) or **Terminal** (on Linux or macOS).
2. Enter the following command, where `<username>` is your remote PC account name and `<server>` is the Nord name or Meshnet IP of the computer you want to access:\
   &#x20;

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">ssh &#x3C;username>@&#x3C;server>
   </code></pre>

   &#x20;\
   **Example**

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">ssh ubuntu@secret.meerkat-andes.nord
   </code></pre>

   or

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">ssh ubuntu@100.96.239.181
   </code></pre>

   &#x20;
3. The first time you connect, you will be asked to verify the authenticity of the server. This message is displayed to make sure you are connecting to the correct remote server. Type `yes` to continue, as shown:

   <div align="left"><figure><img src="/files/FQ8sJozKdan7VzHCMhB1" alt="SSH key fingerprint confirmation"><figcaption></figcaption></figure></div>

   &#x20;
4. Enter the password for the specified username.

The SSH connection will be established, and you will have access to the host device’s terminal. However, for now, both terminal instances work separately.

## Controlling tmux <a href="#controlling-tmux" id="controlling-tmux"></a>

With tmux installed and SSH configured, you can start using the terminal-sharing capabilities of tmux.

### Start a shared session <a href="#start-a-shared-session" id="start-a-shared-session"></a>

On the host device’s terminal, run the following command, where `<SessionName>` is any name for the session:

{% code overflow="wrap" %}

```bash
tmux new -s <SessionName>
```

{% endcode %}

**Example:**

{% code overflow="wrap" %}

```bash
tmux new -s MeshnetSession
```

{% endcode %}

The terminal window will update and clear any commands that were entered previously.

### Join a shared session <a href="#join-a-shared-session" id="join-a-shared-session"></a>

After accessing the host via SSH, run the following command, replacing `<SessionName>` with the name of the active tmux session:

{% code overflow="wrap" %}

```bash
tmux attach -t <SessionName>
```

{% endcode %}

**Example**

{% code overflow="wrap" %}

```bash
tmux attach -t MeshnetSession
```

{% endcode %}

The terminal window will update, and you will be connected to the tmux shared session.

While you are attached to the tmux session, the terminal will update on both devices in real time. This means that any input on one machine will be seen on the other.

### Detach from a shared session <a href="#detach-from-a-shared-session" id="detach-from-a-shared-session"></a>

If you wish to disconnect from the tmux session without fully stopping it, you can do so by pressing **Ctrl** + **B** and **D** on your keyboard or running:

{% code overflow="wrap" %}

```bash
tmux detach
```

{% endcode %}

### Stop a shared session <a href="#stop-a-shared-session" id="stop-a-shared-session"></a>

If you wish to fully stop the tmux session, you can use the following command:

{% code overflow="wrap" %}

```bash
tmux kill-session
```

{% endcode %}

For additional tmux commands and options, refer to the [tmux manual page](http://man.openbsd.org/OpenBSD-current/man1/tmux.1).

You may now securely collaborate using only one terminal instance between two or more remote devices.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://meshnet.nordvpn.com/how-to/joint-projects/pair-programming-tmux.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
