pense-bête de bruno sanchiz

Accueil > Linux > Lignes de commandes > Exécuter un programme root avec ssh/pkexec

Exécuter un programme root avec ssh/pkexec

Publié le 18 juin 2021, dernière mise-à-jour le 19 décembre 2025, > 20 visites, >> 192614 visites totales.

L’idée est de se logguer sur un ordinateur distant et d’ouvrir un programme root/super utilisateuren ligne de commande.

je ne comprends pas bien pkexec,donc

après s’être logguer par ssh -X machin@OrdiDistant , on lance la commande normale par exemple

machin@ccc:~$ sudo gparted

si ça ne marche, on doit voir cannot open display: localhost:10.0
on rajoute alors env DISPLAY=localhost:10.0 XAUTHORITY=/home/machin/.Xauthority donc :

machin@ccc:~$ env DISPLAY=localhost:10.0 XAUTHORITY=/home/machin/.Xauthority sudo gparted


Exemple d’exécution de /usr/bin/nm-connection-editor par ssh

Ouvrir 2 liaisons ssh.
Sur la première, taper
echo $$
On obtient un pid : 2319

Sur le deuxième,

$ pkttyagent --process 2319

Sur la première, taper
pkexec  /usr/bin/nm-connection-editor

Sur le deuxième, apparaît

==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authentication is needed to run `/usr/bin/nm-connection-editor' as the super user
Authenticating as: machin,,, (machin)
Password: 
==== AUTHENTICATION COMPLETE ===


Password: 
==== AUTHENTICATION COMPLETE ===

archives

après s’être logguer par ssh -X machin@OrdiDistant , on lance l’une des lignes suivantes :
marchent :
$ pkexec env DISPLAY=localhost:10.0 XAUTHORITY=/home/machin/.Xauthority sudo /usr/sbin/gparted
# pkexec env DISPLAY=localhost:10.0 XAUTHORITY=/home/machin/.Xauthority /usr/sbin/gparted
ne marchent pas :
$ pkexec /usr/sbin/gparted
$ pkexec env DISPLAY=localhost:10.0 XAUTHORITY=/home/machin/.Xauthority /usr/sbin/gparted
$ pkexec env DISPLAY=localhost:10.0 XAUTHORITY=/home/machin/.Xauthority sudo /usr/sbin/gparted
# pkexec env DISPLAY=$DISPLAY XAUTHORITY=/home/machin/.Xauthority gparted

[bruno sanchiz]