# Setting Up X11 Forwarding

If your program requires the use of a graphical interface, you can stream a window over to your local machine by using X11 forwarding. However, the method to set up this feature is different on each operating system, so check the guides below to get started.

Setting up X11-Forwarding on a Windows machine requires three steps: installing and running an X server, setting a Windows environment variable, and connecting to Monsoon. The first two steps mentioned only need to be performed once as they set up your machine.

## Installing an X Server

SSH alone cannot convert a Linux windowing system over to Windows, so we will need a program to do that for us.

An X server that has been tested to work with Monsoon is *Xming*. You can download the program [from their website](<http://www.straightrunning.com/XmingNotes/>) or by using the following *winget* command:

```powershell
winget install Xming
```

Once you have Xming installed, search for `Xming` in the Start Menu and run it. The process will run in the background and will show a system tray icon.

> [!NOTE]
>
> Xming does not start with your system automatically. You will need to start Xming each time you start your computer to use X11 forwarding.

## Setting Necessary Environment Variables

Next, we need to tell SSH where to stream the window contents. In Windows, all you have to do is set an environment variable. In a terminal, enter the following command to set the `DISPLAY` environment variable:

```powershell
setx DISPLAY localhost:0
```

This variable is set within Windows for only your user, but won't be loaded until your terminal is reopened.

> [!NOTE]
>
> You need to restart your terminal before continuing to load the environment variable you set previously.

## Connecting to Monsoon with X11 Forwarding

Once the previous steps above are complete, there's only one step left: connecting to Monsoon! This is as simple as running the following command in a terminal:

```powershell
ssh -Y [UID]@monsoon.hpc.nau.edu
```

> [!NOTE]
>
> If you are a classroom Monsoon user, you **MUST** replace `monsoon` with `rain`.

From here, it will appear to be a regular SSH session because we haven't started any graphical applications yet. The simplest way to test if the connection worked is by running the *gedit* application:

```bash
$ gedit
```

If a window with a text editor opens, then you are done setting up X11 forwarding on Windows.

## Installing an X Server

On Mac, the installation of an X server requires the use of an external application. We recommend installing and running [XQuartz](<https://www.xquartz.org/>).

### Troubleshooting XQuartz

If you are having a problem getting X11 forwarding working on a Mac, you may need to edit your `/private/etc/ssh/sshd_config` file and add the following line:

```text
X11Forwarding yes
```

## Connecting to Monsoon with X11 Forwarding

To connect to Monsoon with X11 forwarding, open a terminal and enter the following command:

```bash
$ ssh -Y [UID]@monsoon.hpc.nau.edu
```

> [!NOTE]
>
> If you are a classroom Monsoon user, you **MUST** replace `monsoon` with `rain`.

From here, it will appear to be a regular SSH session because we haven't started any graphical applications yet. The simplest way to test if the connection worked is by running the `gedit` application:

```bash
$ gedit
```

If the `gedit` program window appears on your desktop, then you are done setting up X11 forwarding.

Desktop Linux distros already have X11 forwarding built in. To connect to Monsoon with X11 forwarding, open a terminal and enter the following command:

```bash
$ ssh -Y [UID]@monsoon.hpc.nau.edu
```

> [!NOTE]
>
> If you are a classroom Monsoon user, you **MUST** replace `monsoon` with `rain`.

From here, it will appear to be a regular SSH session because we haven't started any graphical applications yet. The simplest way to test if the connection worked is by running the `gedit` application:

```bash
$ gedit
```

If the `gedit` program window appears on your desktop, then you are done setting up X11 forwarding.

## Troubleshooting

### X11 connection rejected because of wrong authentication

This error occurs when the file `~/.Xauthority` cannot be created. Check to see if you have reached your quota limit with the `getquotas` command.
