# Open as Admin

There are cases when you may need to open and edit a file as administrator (as a rule, when you need to edit configuration files in your root directory.

{% hint style="danger" %}
Be extremely careful when changing `/root` files. Unthoughtful actions can break your system.

Always be absolutely sure in what you are doing!
{% endhint %}

You can always use your Terminal and command line to open and edit files as root. Still, command line is not comfortable for everyone to use.

In elementary OS, you can open a new window of the file manager as administrator first and then open and edit all files. But a more convenient way to open a single file from the Pantheon file manager is to create a context menu item **Edit as Admin** (create a new contract file).

1. Open your Terminal and run:

```
cd /usr/share/contractor
```

2. Create a new contract file by running the following:

```
sudo nano io.elementary.code.open-as-root.contract
```

3. Enter your admin password.
4. Insert the following info to the created file:

```
[Contractor Entry]
Name=Edit as Administrator
Icon=io.elementary11oko.code
Description=Edit file via root user privilege
MimeType=text/plain;
Exec=pkexec io.elementary.code %U
Gettext-Domain=code
```

5. Press <mark style="background-color:blue;">Ctrl</mark>+<mark style="background-color:blue;">O</mark> to save, and <mark style="background-color:blue;">Ctrl</mark>+<mark style="background-color:blue;">X</mark> to exit.

Now when you secondary click a root file in the file manager, you can see the **Edit as Administrator** context menu item.

<figure><img src="/files/kQAj7xjriExEavrP3eIj" alt=""><figcaption></figcaption></figure>

Click to open, submit your admin password, and edit the file.

{% hint style="info" %}
All thanks to [Tiwo Satriatama](https://www.youtube.com/@tiwosatriatama) for the manual. Watch the [video guide here](https://youtu.be/jsw7LiXATAc?si=ixWI0tAyGZYFKYIs).
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://da-home-studio.gitbook.io/elementary-os-user-handbook/best-practices/2-advanced/open-as-admin.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.
