> For the complete documentation index, see [llms.txt](https://docs-jupyter.davidjachochavez.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-jupyter.davidjachochavez.org/optional-github-authentication/generate-cookie-secret.md).

# Generate Cookie Secret

Encrypt your lab's [cookie](https://en.wikipedia.org/wiki/HTTP_cookie) for security purposes:

{% hint style="info" %}
Obtain administrative rights by requesting root access:
{% endhint %}

```
sudo -i
```

Create a new directory for the cookie secret:

```
mkdir /srv/jupyterhub
```

Generate a random number and save it as the cookie secret:

```
openssl rand -hex 32 > /srv/jupyterhub/jupyterhub_cookie_secret
```

Edit JupyterHub's configuration file:

```
nano /etc/jupyterhub/jupyterhub_config.py
```

Copy the following and add it to the file:

```
c.JupyterHub.cookie_secret_file = '/srv/jupyterhub/jupyterhub_cookie_secret'
```

Use CTRL+O then enter to overwrite the document and CTRL+X to exit.

Ensure that only the system administrator can read and write the cookie secret:

```
chmod 600 /srv/jupyterhub/jupyterhub_cookie_secret
```

Restart to ensure recognition of the new extension:

```
systemctl restart jupyterhub.service
```
