Grafische Anwendung als root starten: Unterschied zwischen den Versionen
Die Seite wurde neu angelegt: „Category:Graphical user interfaces Category:Security ja:root で X アプリケーションを起動 pt:Running GUI applications as root {{Warning|1=All of the following methods have security implications that users should be aware of. As [https://bugzilla.gnome.org//show_bug.cgi?id=772875#c5 described] by Emmanuele Bassi, a GNOME developer: :[...] there are no *real*, substantiated, technological reasons why anybody should run a GUI app…“ |
Keine Bearbeitungszusammenfassung |
||
Zeile 1: | Zeile 1: | ||
[[Category:Graphical user interfaces]] | [[Category:Graphical user interfaces]] | ||
[[Category:Security]] | [[Category:Security]] | ||
:[...] there are no *real*, substantiated, technological reasons why anybody should run a GUI application as root. By running GUI applications as an admin user you are literally running millions of lines of code that have not been audited properly to run under elevated privileges; you are also running code that will touch files inside your $HOME and may change their ownership on the file system; connect, via IPC, to even more running code, etc. | |||
:You are opening up a massive, gaping security hole [...]. | ; Warning | ||
All of the following methods have security implications that users should be aware of. As [https://bugzilla.gnome.org//show_bug.cgi?id=772875#c5 described] by Emmanuele Bassi, a GNOME developer | |||
: [...] there are no *real*, substantiated, technological reasons why anybody should run a GUI application as root. By running GUI applications as an admin user you are literally running millions of lines of code that have not been audited properly to run under elevated privileges; you are also running code that will touch files inside your $HOME and may change their ownership on the file system; connect, via IPC, to even more running code, etc. | |||
: You are opening up a massive, gaping security hole [...]. | |||
Avoid running graphical applications as [[root user|root]] if possible, see [[#Circumvent running graphical applications as root]]. | Avoid running graphical applications as [[root user|root]] if possible, see [[#Circumvent running graphical applications as root]]. | ||
== Circumvent running graphical applications as root == | == Circumvent running graphical applications as root == | ||
=== sudoedit === | === sudoedit === | ||
Zeile 18: | Zeile 16: | ||
=== GVFS === | === GVFS === | ||
Access to privileged files and directories is possible through [[GVFS]] by specifying the {{ic|admin}} [https://wiki.gnome.org/Projects/gvfs/backends backend] in the URI scheme[https://bugzilla.redhat.com/show_bug.cgi?id=1274451#c27][https://bugzilla.gnome.org//show_bug.cgi?id=772875#c2], e.g.: | Access to privileged files and directories is possible through [[GVFS]] by specifying the {{ic|admin}} [https://wiki.gnome.org/Projects/gvfs/backends backend] in the URI scheme[https://bugzilla.redhat.com/show_bug.cgi?id=1274451#c27][https://bugzilla.gnome.org//show_bug.cgi?id=772875#c2], e.g.: | ||
Zeile 30: | Zeile 27: | ||
== Xorg == | == Xorg == | ||
By default, and for security reasons, root will be unable to connect to a non-root user's [[X server]]. There are multiple ways of allowing root to do so however, if necessary. | By default, and for security reasons, root will be unable to connect to a non-root user's [[X server]]. There are multiple ways of allowing root to do so however, if necessary. | ||
Zeile 36: | Zeile 32: | ||
=== Punctual methods === | === Punctual methods === | ||
These methods wrap the application in an elevation framework and drop the acquired privileges once it exits: | These methods wrap the application in an elevation framework and drop the acquired privileges once it exits: | ||
* {{man|1|kdesu}} (from {{Pkg|kde-cli-tools}}) | |||
$ kdesu ''application'' | $ kdesu ''application'' | ||
Zeile 49: | Zeile 44: | ||
=== Alternate methods === | === Alternate methods === | ||
These methods will allow root to connect to a non-root user's X server, but present varying levels of security risks, especially if you run ssh. If you are behind a firewall, you may consider them to be safe enough for your requirements. | These methods will allow root to connect to a non-root user's X server, but present varying levels of security risks, especially if you run ssh. If you are behind a firewall, you may consider them to be safe enough for your requirements. | ||
==== Xhost ==== | ==== Xhost ==== | ||
[[Xhost]] can be used to temporarily allow root access. | [[Xhost]] can be used to temporarily allow root access. | ||
==== Permanently allow root access ==== | ==== Permanently allow root access ==== | ||
; Method 1 | |||
Add the line | |||
session optional pam_xauth.so | session optional pam_xauth.so | ||
to both | to both /etc/pam.d/su and /etc/pam.d/su-l. Then switch to your root user using su or su -. | ||
; Method 2 | |||
Globally in /etc/profile | |||
Add the following line to | Add the following line to /etc/profile: | ||
; /etc/profile | |||
export XAUTHORITY=/home/username/.Xauthority | |||
export XAUTHORITY=/home/ | |||
This will permanently allow root to connect to a non-root user's X server. | This will permanently allow root to connect to a non-root user's X server. | ||
Or, merely specify a particular app | Or, merely specify a particular app | ||
# XAUTHORITY=/home/''username''/.Xauthority ''appname'' | # XAUTHORITY=/home/''username''/.Xauthority ''appname'' | ||
where | where ''appname'' is the name of the particular app. (e.g. ''kwrite'') | ||
== Wayland == | == Wayland == | ||
Trying to run a graphical application as root via [[su]], [[sudo]] or [[polkit|pkexec]] in a Wayland session (e.g. [[GParted]] or [[Gedit]]), will fail with an error similar to this: | Trying to run a graphical application as root via [[su]], [[sudo]] or [[polkit|pkexec]] in a Wayland session (e.g. [[GParted]] or [[Gedit]]), will fail with an error similar to this: | ||
Version vom 10. Februar 2025, 20:29 Uhr
- Warning
All of the following methods have security implications that users should be aware of. As described by Emmanuele Bassi, a GNOME developer
- [...] there are no *real*, substantiated, technological reasons why anybody should run a GUI application as root. By running GUI applications as an admin user you are literally running millions of lines of code that have not been audited properly to run under elevated privileges; you are also running code that will touch files inside your $HOME and may change their ownership on the file system; connect, via IPC, to even more running code, etc.
- You are opening up a massive, gaping security hole [...].
Avoid running graphical applications as root if possible, see #Circumvent running graphical applications as root.
Circumvent running graphical applications as root
sudoedit
To edit files as root, use sudoedit.
GVFS
Access to privileged files and directories is possible through GVFS by specifying the Vorlage:Ic backend in the URI scheme[1][2], e.g.:
$ nautilus admin:///root/
or
$ gedit admin:///etc/fstab
Xorg
By default, and for security reasons, root will be unable to connect to a non-root user's X server. There are multiple ways of allowing root to do so however, if necessary.
The proper, recommended way to run GUI applications under X with elevated privileges is to create a Polkit policy, as shown in this forum post. This should however "only be used for legacy programs", as Vorlage:Man reminds. Applications should rather "defer the privileged operations to an auditable, self-contained, minimal piece of code that gets executed after doing a privilege escalation, and gets dropped when not needed"[3]. This may be the object of a bug report to the upstream project.
Punctual methods
These methods wrap the application in an elevation framework and drop the acquired privileges once it exits:
- Vorlage:Man (from Vorlage:Pkg)
$ kdesu application
- sudo (must be properly configured)
$ sudo application
- Vorlage:AUR (wrapper around su which will transfer your X credentials)
$ sux root application
Alternate methods
These methods will allow root to connect to a non-root user's X server, but present varying levels of security risks, especially if you run ssh. If you are behind a firewall, you may consider them to be safe enough for your requirements.
Xhost
Xhost can be used to temporarily allow root access.
Permanently allow root access
- Method 1
Add the line
session optional pam_xauth.so
to both /etc/pam.d/su and /etc/pam.d/su-l. Then switch to your root user using su or su -.
- Method 2
Globally in /etc/profile
Add the following line to /etc/profile:
- /etc/profile
export XAUTHORITY=/home/username/.Xauthority
This will permanently allow root to connect to a non-root user's X server.
Or, merely specify a particular app
# XAUTHORITY=/home/username/.Xauthority appname
where appname is the name of the particular app. (e.g. kwrite)
Wayland
Trying to run a graphical application as root via su, sudo or pkexec in a Wayland session (e.g. GParted or Gedit), will fail with an error similar to this:
Before Wayland, running GUI applications with elevated privileges could be properly implemented by creating a Polkit policy, or more dangerously done by running the command in a terminal by prepending the command with Vorlage:Ic; but under (X)Wayland this does not work anymore as the default has been made to only allow the user who started the X server to connect clients to it (see the bug report and the upstream commits it refers to).
Avoid running graphical applications as root if possible, see #Circumvent running graphical applications as root.
A more versatile though more insecure workaround allows any graphical application to be run as root #Using xhost.
Using xhost
A more versatile —though much less secure— workaround is to use xhost to temporarily allow the root user to access the local user's X session[4]. To do so, execute the following command as the current (unprivileged) user:
$ xhost si:localuser:root
To remove this access after the application has been closed:
$ xhost -si:localuser:root
Using sudo -E
You can launch an application with:
$ sudo -E program
which preserves environment variables like WAYLAND_DISPLAY.
If you want the HOME environment variable to be set to the target user, use:
$ sudo -EH program
See Vorlage:Man.
Using pkexec
You can launch GUI an application with:
$ pkexec env WAYLAND_DISPLAY="$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" XDG_RUNTIME_DIR=/run/user/0 program
which preserves the environment variable WAYLAND_DISPLAY.