# 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
```


---

# 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://docs-jupyter.davidjachochavez.org/optional-github-authentication/generate-cookie-secret.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.
