Linux tip: how to get graphical application works after sudo

When connected remotely through ssh and wanting to use a graphical application that requires root privileges and X11 access, sudo is often a barrier to overcome.

Hypothesis:

  • the SSH target server allows X11Forwarding in OpenSSH sshd_config
  • a X server is running on the workstation running ssh client
  • sudoers allow connected user to invoke the expected application startup command with parameters

Here the process:

  • connect with X11 forwarding -X ssh option or enable it globally in client /etc/ssh/ssh_config (for Debian) with ForwardX11,
  • set XAUTHORITY variable to point to user’s X11 cookie generated by ssh X11 tunneling
  • and finally run the application as root with sudo

Now an example of commands to invoke to use the famous network traffic analyzer wireshark:

user@workstation $ ssh -X targetserver.domain.com
user@targetserver.domain.com's password:

user@targetserver $ export XAUTHORITY=/home/user/.Xauthority

user@targetserver $ sudo wireshark
[sudo] password for user:

I have not found easier and faster yet,
Hope this help

Laisser un commentaire