# Add a Peer

Say we want to connect two computers via wireguard. We will call them **one** and **two**.

## Manual

On one, run the following command to add a new host:
```
sudo wg set wg0 peer ${two_pubkey:?} endpoint ${two_public_ip:?}:${two_port:?} allowed-ips ${two_wg_ip:?}/32
```
if we also want to be able to refer to the host by an easy to remember name rather than just an IP, we can also add it to `/etc/hosts`
```
echo -e "${two_wg_ip:?}\t${two_hostname}.wg.alemor.org" >> /etc/hosts
```

On two, run the same commands but with one and two switched.

## Automatic

If you can ssh into an account that has sudo access on the host, simply run the `wg-peer` command included in the `bin` section of this repo.