1

Is there a new way to launch nautilus from a basic script?

#!/bin/bash
echo "Open File Manager as Root"
sudo nautilus

Opening from Nautilus scripts context menu does not launch Nautilus if sudo is present (opens Nautilus from the scripts context menu if sudo is removed), however, his opens Nautilus with password prompt if run as a program.

Tried:

nautilus admin:///home/

Tried this, but does not work for me, just generates an error when Nautilus launches. Policykit1 error, does not have a uid set

Suggestions here but none of this works, or the answer is unclear and I am missing something.

Note: When trying to launch any script with sudo in from the Nautilus script menu, none of these scripts will launch.

Tried:

sudo apt-get install nautilus-admin

This did not work, Policykit1 error

Found this here that got Open as Administrator to work here

sudo add-apt-repository ppa:ubuntuhandbook1/gvfs
sudo apt install gvfs-fuse
sudo apt install gvfs

Reboot

How to Restore GVfs to stock version:

sudo apt install ppa-purge && sudo ppa-purge ppa:ubuntuhandbook1/gvfs

I found that this worked for me:

#!/bin/bash 
gnome-terminal -- sh -c 'echo "sudo nautilus" | bash'

Now when I use the Nautilus script menu I can launch a root Nautilus session.

This also worked as suggested below:

#!/bin/bash
pkexec env DISPLAY="$DISPLAY" XAUTHORITY="$XAUTHORITY" nautilus
pst007x
  • 8,052

2 Answers2

1

I believe you are looking for pkexec. This works on my system to launch nautilus as root with a graphical password prompt:

#!/bin/bash

pkexec env DISPLAY="$DISPLAY" XAUTHORITY="$XAUTHORITY" nautilus

You need to set the DISPLAY and XAUTHORITY variables to be able to launch GUI programs with pkexec, but it should work like gksu used to.

terdon
  • 100,812
0

Try

sudo -E nautilus

I don't have nautilus, but my own fillemanger works that way.

JdeHaan
  • 439
  • 1
    Thanks, the same issue. When trying to launch any script with sudo in from the Nautilus script menu, nothing will launch. I installed Dolphin, and that works like a dream. – pst007x Feb 20 '22 at 12:07