AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1180983
Accepted
zpangwin
zpangwin
Asked: 2019-10-15 18:19:48 +0800 CST2019-10-15 18:19:48 +0800 CST 2019-10-15 18:19:48 +0800 CST

nautilus/nemo/other 文件管理器 - 对更易于访问的基于 GUI 的所有者管理的建议?

  • 772

精简版

TL;DR - 当以提升的权限*运行 nemo/nautilus 时,权限选项卡上有大量的用户/组......他们都被卡在没有任何热键支持的不可搜索的下拉列表中。寻找调整/替代文件管理器/chmod gui-wrappers,这样我就可以从 GUI 更改所有权,而不会出现可访问性的噩梦。有什么建议么?


更多信息

我在 Virtualbox 中安装了几个版本的 Ubuntu 18.04。到目前为止,我主要使用Cinnamon desktop /nemo。

大多数情况下,我对这个桌面非常满意。但是基于 GUI 的所有权更改(从根)令人沮丧,因为大量条目被卡在一个下拉列表中,我无法搜索并且无法使用热键(例如,按下r以跳转到“根”等) . 启动终端是可靠的,但当我赶时间时输入名称很慢。

注意:当从非 root 帐户运行文件管理器时,这并不是真正的问题,因为所有者不可编辑并且只显示几个组。

我通常会遇到这个问题,我正在尝试修复当前用户不拥有的共享文件夹上的拙劣所有权权限。而且它通常永远不会像运行单个chown -R命令那样快速和简单。

我在以下位置遇到了相同的可访问性设计:

  • nemo v.3.6.5 (ubuntu 18.04/gnome+cinnnamon)
  • nemo v4.2.3(在一个流行的子发行版中,我显然不再允许在这里提及)
  • 鹦鹉螺 v3.26.4 (ubuntu 18.04/gnome)。

标准:

我有兴趣找到满足这些标准的基于 GUI 的解决方案:

  • 适用于 Ubuntu 18.04 / 仿生的某种风格(我更喜欢 LTS 版本)
  • 50-100 个用户/组列表的良好用户可访问性(例如,至少尝试处理重要的列表大小,例如通过热键支持、搜索过滤器、隐藏服务帐户的选项或其他方式)
  • 在根目录下运行没有问题(例如通过pkexec或其他)。之所以提到这一点,是因为在完全拒绝在 root 下运行之前,我已经运行了一些应用程序。

在这一点上,我只是希望有人知道我不知道的选项......我并不特别关心这是不是特定于 nemo 的调整、系统配置、一些模糊的构建选项、不同的文件管理器/desktop 环境,一些包含 GUI 的外部应用程序chown(只要我可以将其放入 anemo-action并传递路径)等。主要是为了避免在启动终端和手动输入更长的名称时出现额外的问题我很急。

* 另外,当我说我“以 root 身份运行”/“以提升的权限运行”时,我的意思是出现在 nemo/nautilus UI 中的选项,而不是我直接使用 sudo / pkexec / 等启动。


查看对话框问题的步骤:

  1. 在桌面或非 root 帐户拥有的任何地方创建一个名为“test”的文件夹
  2. 在 Nemo 中,右键单击 > “以 root 身份打开” > 输入密码。或者对于 nautilus,运行pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY nautilus以管理员权限打开。
  3. 使用管理实例,右键单击“测试”文件夹 > 属性 > 权限选项卡
  4. 请注意,所有服务帐户和组都显示而无法过滤它们/没有复选框来隐藏它们。请注意,在下拉菜单中按“R”不会跳转到或选择“root”(或以“R”开头的第一个帐户)。在我的例子中,显示了 50 个用户(其中​​ 3 个是非服务帐户)和 80 个组(其中 8 个与服务帐户无关)。对我来说,这是一个可访问性的噩梦,它使搜索内容几乎与需要启动终端并手动输入一样痛苦。

我试过的:

如果我发现任何可行的方法,我会跟进,但到目前为止,我已经尝试了以下方法:

  • 许可证几乎正是我正在寻找的东西,只是它似乎需要输入名称而不是从列表/下拉列表/等中选择。不幸的是,我目前的 GTK 技能绝对为零(尽管如果没有人有更好的建议,我可能会在有更多时间时重新审视这个)。
  • Ubuntu 18.04.2/gnome - 最初无法弄清楚如何以 root 身份运行,但pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY nautilus最终成功了。毫不奇怪,这似乎与 nemo 有相同的问题。
  • Ubuntu 18.04.2/cinnamon -如上所述安装 cinnamon并运行 nemo 后,这并不能满足我的要求。
  • Kubuntu 18.04 - 找不到以 root 身份启动 dolphin 的方法,因此无法测试。在 livedisc 上作为默认的非 root 帐户运行时,用户/组字段对我来说是灰色的。听起来这是 v17 的一个问题,我必须让 v18 甚至有机会以 root 身份运行。
  • 更新 1:发现这个网站提到了 Eiciel。尝试了一下sudo apt install -y eicieland touch /tmp/foo.txt && eiciel /tmp/foo.txt... 看起来很酷,但不幸的是,要么它不允许更改所有者,要么我只是不知道如何去做(似乎将用户/组添加到 ACL,而不是替换当前的所有者/组) .
  • 更新 2:在基于 ubuntu 18.04 的子发行版上测试了 thunar。当我运行它sudo thunar /并转到权限选项卡时,组下拉列表与 nemo/nautilus 有相同的问题,尽管以 root 身份运行,它甚至根本不允许我编辑用户。
  • 更新 3:在 kubuntu 中使用 krusader 进行测试。以 root 身份运行,在权限对话框中,所有者/拥有组字段只是文本输入字段(例如,您必须输入它)。

截屏

在 (admin/root/pkexec) nemo 和 nautilus > properties > Permissions 选项卡中出现的包含大量条目且不支持热键的不可搜索下拉列表。

包含大量条目且不支持热键的不可搜索下拉列表

nautilus permissions filemanager ownership nemo
  • 1 1 个回答
  • 1493 Views

1 个回答

  • Voted
  1. Best Answer
    zpangwin
    2019-10-16T03:56:24+08:002019-10-16T03:56:24+08:00

    更新:没有听到任何其他回复,自从我更新它以添加多选支持以来,这一直工作得更好,所以我想,缺乏任何其他选项,我会接受这个作为我的答案

    更新#2:我已经创建了一个脚本来完成所有繁重的工作并为您自动执行以下步骤。您可以在我的 github中找到有关该脚本的更多信息。


    我仍然对其他答案非常感兴趣,但我至少找到了一个有点骇人听闻的解决方法(bash + yad + pkexec),我认为它总比没有好......也继续并将其作为功能请求提交 nemo项目,所以希望其中一个人能找到比我这里更好的东西。

    假设

    我的解决方法假设如下:

    • 您已安装 yad:sudo apt install -y yad
    • 您不介意在单独的对话框中编辑用户/组(例如根本不处理 chmod 的东西;只有 chown)
    • 您不介意为初始设置做一些跑腿工作
    • 您可以接受我非常简单的用户/组选择。
    • 您可以接受不支持按键/自动完成的下拉菜单。
    • policykit 的东西使非 root nemo (每次)都得到一个身份验证提示,但 root nemo 永远不会得到提示。如果您想降低安全性(不推荐),您可以随时更改策略包设置。
    • 您相信我没有弄乱策略包设置(它为我运行并且似乎提示正确,但我不保证安全性)
    • 由于在幕后切换到 bash 脚本而导致性能不佳,您可以接受

    设置

    这将需要创建 3 个文件并编辑第四个文件(用于策略包定义)。

    1. 首先,继续创建一个临时文件夹和 3 个临时文件:
    mkdir /tmp/chown-gui
    cd /tmp/chown-gui
    # create temp files - we'll rename these later when they get moved
    touch tmp-pkexec tmp-sh tmp-action
    
    1. 创建主 bash 脚本

    文件 #1:tmp-sh(将在 /usr/bin/chown-gui-wrapper 结束)

    #!/bin/bash
    
    # v1.2.0
    # Last updated on 2019 Oct 15
    
    prompt_on_multiple_files="true";
    default_to_once_for_all_paths_if_no_prompt="true";
    apply_once_for_all_paths="false";
    
    has_multiple_paths="false";
    second_file="$2";
    if [[ "" != "${second_file}" ]]; then
        has_multiple_paths="true";
    
        if [[ "true" == "${prompt_on_multiple_files}" ]]; then
            prompt_response=$( yad --center --button="gtk-ok:0" --title "Multiple Paths Detected" --form --field="\n    How would you like to apply permissions?    \n:LBL" "" --field="${label_hpadding}:CB" "Set permissions once and apply it to all paths\!Set permissions for each path individually");
            if [[ ! $prompt_response =~ ^.*individually.*$ ]]; then
                apply_once_for_all_paths="true";
            fi
        elif [[ "true" == "${default_to_once_for_all_paths_if_no_prompt}" ]]; then
            apply_once_for_all_paths="true";
        fi
    fi
    
    #echo "prompt_on_multiple_files=\"${prompt_on_multiple_files}\"";
    #echo "default_to_once_for_all_paths_if_no_prompt=\"${default_to_once_for_all_paths_if_no_prompt}\"";
    #echo "apply_once_for_all_paths=\"${apply_once_for_all_paths}\"";
    
    popup_title="Please select the user and group owners";
    popup_text="Please select the user and group owners for the following path:"
    label_hpadding="    ";
    
    for filepath in "${@}"; do
        #echo "filepath in array is $filepath";
    
        if [[ ! -e "${filepath}" ]]; then
            ERROR_MSG="ERROR: File '${filepath}' does not exist";
            notify-send --icon=error "${ERROR_MSG}";
            echo "${ERROR_MSG}";
            continue;
        fi
        filename=$(basename "${filepath}")
        current_user=$(stat -c "%U" "${filepath}");
        current_group=$(stat -c "%G" "${filepath}");
    
        show_checkbox="false";
        if [[ -d "${filepath}" ]]; then
            show_checkbox="true";
        fi
    
        # get list of non-service accounts/groups
        users_list=$(getent passwd {1000..60000}|awk -F: '{print $1}'|tr '\n' ' ');
        groups_list=$(getent group {1000..60000}|awk -F: '{print $1}'|tr '\n' ' ');
    
        sorted_user_list=$(echo $(printf '%s\n' root $users_list | sort -u)|sed -E "s/\\b($current_user)\\b/^\\1/g"|tr ' ' '\!');
        sorted_group_list=$(echo $(printf '%s\n' root $groups_list | sort -u)|sed -E "s/\\b($current_group)\\b/^\\1/g"|tr ' ' '\!');
    
        #echo "show_checkbox: ${show_checkbox}";
        if [[ "true" == "${show_checkbox}" ]]; then
            formdata=$(yad --center --button="gtk-cancel:1" --button="gtk-ok:0" --title "${popup_title}" --form --field="\n${label_hpadding}${popup_text}${label_hpadding}\n:LBL" "" --field="${label_hpadding}Path:${label_hpadding}:RO" "${filepath}" --field="${label_hpadding}User:${label_hpadding}:CBE" "${sorted_user_list}" --field="${label_hpadding}Group:${label_hpadding}:CBE" "${sorted_group_list}" --field "\n:LBL" "" --field="Apply Recursively?:CHK" "FALSE");
        else
            formdata=$(yad --center --button="gtk-cancel:1" --button="gtk-ok:0" --title "${popup_title}" --form --field="\n${label_hpadding}${popup_text}${label_hpadding}\n:LBL" "" --field="${label_hpadding}Path:${label_hpadding}:RO" "${filepath}" --field="${label_hpadding}User:${label_hpadding}:CBE" "${sorted_user_list}" --field="${label_hpadding}Group:${label_hpadding}:CBE" "${sorted_group_list}");
        fi
        if [[ "" == "$formdata" ]]; then
            echo "user pressed cancel for filepath '${filepath}'";
            continue;
        fi
        #echo "formdata=\"${formdata}\"";
    
        new_user=$(echo "${formdata}"|awk -F'|' '{print $3}');
        new_group=$(echo "${formdata}"|awk -F'|' '{print $4}');
        is_recursive="FALSE";
        if [[ "true" == "${show_checkbox}" ]]; then
            is_recursive=$(echo "${formdata}"|awk -F'|' '{print $6}');
        fi
        #echo "new_user=\"${new_user}\"";
        #echo "new_group=\"${new_group}\"";
        #echo "is_recursive=\"${is_recursive}\"";
    
        RECURSIVE_FLAG='';
        if [[ "TRUE" == "${is_recursive}" ]]; then
            RECURSIVE_FLAG='-R';
        fi
    
        if [[ "true" == "${has_multiple_paths}" && "true" == "${apply_once_for_all_paths}" ]]; then
            chown $RECURSIVE_FLAG "${new_user}":"${new_group}" "${@}";
            break;
        else
            chown $RECURSIVE_FLAG "${new_user}":"${new_group}" "${filepath}";
        fi
    done
    
    1. 创建包装脚本

    文件 #2:tmp-pkexec(将在 /usr/bin/pkexec-chown-gui-wrapper 结束)

    #!/bin/bash
    
    # v1.2.0
    # Last Updated: 2019 Oct 15
    
    yad_installed=$(which yad);
    if [[ "" == "${yad_installed}" ]]; then
        ERROR_MSG="ERROR: Missing dependency 'yad'; Please run: sudo apt install -y yad;";
        notify-send --icon=error "${ERROR_MSG}";
        echo "${ERROR_MSG}";
        exit;
    fi
    
    pkexec --user root env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY /usr/bin/chown-gui-wrapper "${@}"
    
    1. 创建 nemo 动作(所以它出现在右键菜单中)

    文件 #3:tmp-action(将在 /usr/share/nemo/actions/change-owner.nemo_action 结束)

    [Nemo Action]
    Name=Change Owner/Group
    Comment=GUI wrapper for chown
    Selection=s
    Exec=/usr/bin/pkexec-chown-gui-wrapper %F
    Icon-Name=gnome-settings
    Extensions=any;
    Quote=double
    
    1. 将所有临时文件复制到适当的位置并设置权限
    cd /tmp/chown-gui
    sudo cp tmp-sh /usr/bin/chown-gui-wrapper;
    sudo cp tmp-pkexec /usr/bin/pkexec-chown-gui-wrapper;
    sudo cp tmp-action /usr/share/nemo/actions/change-owner.nemo_action;
    
    sudo chown root:root /usr/bin/chown-gui-wrapper;
    sudo chown root:root /usr/bin/pkexec-chown-gui-wrapper;
    sudo chown root:root /usr/share/nemo/actions/change-owner.nemo_action;
    
    sudo chmod 755 /usr/bin/chown-gui-wrapper;
    sudo chmod 755 /usr/bin/pkexec-chown-gui-wrapper;
    sudo chmod 644 /usr/share/nemo/actions/change-owner.nemo_action;
    # This part is needed if you want to be able to use this in nemo with
    # single-file selections AND multiple-file selections BUT NOT when
    # there is NO selection (e.g. directory background).
    # Nemo's 'Selection' option doesn't currently allow multiple values
    #   and 'm' only considers "2+" and 'a' considers "0+"
    # whereas this gives us "1,2+"
    #
    sudo cp -a /usr/share/nemo/actions/change-owner.nemo_action /usr/share/nemo/actions/change-owner-single-file.nemo_action;
    sudo mv /usr/share/nemo/actions/change-owner.nemo_action /usr/share/nemo/actions/change-owner-multiple-files.nemo_action;
    sudo sed -i -E 's/^(Selection)=s/\1=m/' /usr/share/nemo/actions/change-owner-multiple-files.nemo_action;
    
    1. 确保已安装 yad。没有它,这绝对行不通。您可能会用 zenity 替换它(但由于 yad 是 zenity 的一个分支,这对我来说似乎毫无意义)
    sudo apt install -y yad
    
    1. 创建策略包例外

    您可能已经有也可能没有 pkexec.policy 文件。如果你这样做,那么你只想添加<action>...</action>块。如果您没有该文件,则创建它(chmod 664和chown root:root:)并复制整个<policyconfig>...</policyconfig>块。

    要编辑/创建的 Policykit 文件: /usr/share/polkit-1/actions/org.freedesktop.policykit.pkexec.policy

    内容(新文件):

    <!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN" "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
    <policyconfig>
      <action id="org.freedesktop.policykit.pkexec.run-chown-gui-wrapper">
        <description>GUI wrapper for chown</description>
        <message>Authentication is required to run chown-gui-wrapper</message>
        <icon_name>gnome-settings</icon_name>
        <defaults>
          <allow_any>no</allow_any>
          <allow_inactive>no</allow_inactive>
          <allow_active>auth_admin_keep</allow_active>
        </defaults>
        <annotate key="org.freedesktop.policykit.exec.path">/bin/bash</annotate>
        <annotate key="org.freedesktop.policykit.exec.argv1">/usr/bin/chown-gui-wrapper</annotate>
        <annotate key="org.freedesktop.policykit.exec.allow_gui">TRUE</annotate>
      </action>
    </policyconfig>
    
    1. 确认设置
    # make dummy file to test with
    echo dummy > /tmp/foo.txt
    
    # check that you get the gui pop-up
    # no need for root, just confirm gui comes up, then you can cancel
    /usr/bin/chown-gui-wrapper /tmp/foo.txt
    
    # check that you get the gui pop-up
    # might prompt for auth, just confirm gui comes up, then you can cancel
    /usr/bin/pkexec-chown-gui-wrapper /tmp/foo.txt
    

    如果从终端启动,则只需确认 nemo 上下文菜单选项有效且一切正常。


    截图/预览

    使用 yad 创建的弹出窗口

    在此处输入图像描述

    它会自动过滤到 root + 非服务用户/组:

    注意:下拉菜单实际上是按 AZ 降序排列的;但我在图像中编辑了我的用户名......因为这是互联网:-)

    在此处输入图像描述

    • 1

相关问题

  • 如何在 Nautilus 中管理保存的完整网页及其目录(例如 n.html 和 n_files)

  • 如何让 Nautilus windows 坚持拖放?[关闭]

  • Nautilus 中的 FTP 连接问题 - 一段时间后似乎超时

  • Ubuntu 在什么许可证下?可以合法修改和分发吗?

  • 文件权限如何工作?文件权限用户和组

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve