V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
opentrade
V2EX  ›  程序员

帮我执行个 Linux 命令,看看兼容性

  •  
  •   opentrade · 2023-06-29 22:28:54 +08:00 · 4955 次点击
    这是一个创建于 520 天前的主题,其中的信息可能已经有所发展或是发生改变。

    分别是提权和取消提权后的结果,并请告知发行版本和桌面环境,谢谢了,拜托

    pkexec echo x; echo $?;
    
    29 条回复    2023-06-30 16:45:04 +08:00
    churchmice
        1
    churchmice  
       2023-06-29 22:34:52 +08:00
    RETURN VALUE
    Upon successful completion, the return value is the return value of PROGRAM. If the
    calling process is not authorized or an authorization could not be obtained through
    authentication or an error occured, pkexec exits with a return value of 127. If the
    authorization could not be obtained because the user dismissed the authentication
    dialog, pkexec exits with a return value of 126.
    Donahue
        2
    Donahue  
       2023-06-29 22:37:44 +08:00   ❤️ 1
    ubuntu22.04
    需要输入密码运行这个命令,运行后得到输出
    x
    0
    coolfan
        3
    coolfan  
       2023-06-29 22:51:03 +08:00   ❤️ 1
    Ubuntu 22.04.2 LTS on Windows 10 x86_64

    ****@LAPTOP-Fan:~$ sudo pkexec echo x; echo $?;
    [sudo] password for ****:
    x
    0
    GeruzoniAnsasu
        4
    GeruzoniAnsasu  
       2023-06-29 22:59:00 +08:00   ❤️ 1
    我遇到了跟这个问题完全一致的现象:

    https://askubuntu.com/questions/799669/etc-sudoers-file-corrupted-and-i-cant-run-pkexec-visudo-over-ssh

    在单会话 SSH 中 auth 失败。
    但 systemctl 这样的提权命令又是能成功通过验证的


    sudo pkexec 正常
    prosixe
        5
    prosixe  
       2023-06-29 22:59:48 +08:00   ❤️ 1
    Error executing command as another user: Request dismissed
    126
    Ubuntu 23.04
    bjzhush
        6
    bjzhush  
       2023-06-29 23:03:43 +08:00   ❤️ 1
    ➜ ~ uname -a
    Linux vultr 5.15.0-58-generic #64-Ubuntu SMP Thu Jan 5 11:43:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
    ➜ ~ cat /etc/issue
    Ubuntu 22.04.2 LTS \n \l

    ➜ ~ pkexec echo x; echo $?;
    x
    0
    ➜ ~
    xiaobai1213
        7
    xiaobai1213  
       2023-06-29 23:06:11 +08:00   ❤️ 1
    oIMOo
        8
    oIMOo  
       2023-06-29 23:06:58 +08:00   ❤️ 1
    admin 账户 sudo 前缀
    x
    0

    Linux itis-bli-20476 5.19.0-43-generic #44~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon May 22 13:39:36 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
    vrqq
        9
    vrqq  
       2023-06-29 23:13:07 +08:00   ❤️ 1
    ```bash
    $ pkexec echo x; echo $?;
    ==== AUTHENTICATING FOR org.freedesktop.policykit.exec ====
    Authentication is needed to run `/usr/bin/echo' as the super user
    Authenticating as: vrqq
    Password:
    polkit-agent-helper-1: error response to PolicyKit daemon: GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: No session for cookie
    ==== AUTHENTICATION FAILED ====
    Error executing command as another user: Not authorized

    This incident has been reported.
    127

    $ sudo pkexec echo x; echo $?;
    x
    0

    $ gnome-shell --version
    GNOME Shell 40.10
    ```

    Red Hat Enterprise Linux release 9.2 (Plow)
    Linux rhedt 5.14.0-284.18.1.el9_2.x86_64
    yanqiyu
        10
    yanqiyu  
       2023-06-30 00:03:24 +08:00   ❤️ 1
    ❯ pkexec echo x; echo $?;
    Error executing command as another user: Request dismissed
    126

    ❯ pkexec echo x; echo $?;
    x
    0

    ❯ cat /etc/redhat-release
    Fedora release 38 (Thirty Eight)
    basncy
        11
    basncy  
       2023-06-30 01:38:37 +08:00
    支持楼主开发桌面 app.

    可以 ps -ef 检查有没有 polkit 进程来接收请求, 没有就返回 127, 有就是 0.

    不同桌面环境进程名不一样, xfce 和 i3 桌面环境是 /usr/lib/xfce-polkit/xfce-polkit

    https://wiki.archlinux.org/title/Polkit
    0superx0
        12
    0superx0  
       2023-06-30 07:48:59 +08:00
    lin@x:~$ pkexec echo x; echo $?;
    x
    0
    lin@x:~$ neofetch
    ##### lin@x
    ####### -----
    ##O#O## OS:ubuntu 18.04 x86_64
    ####### Host: 2325GB6 ThinkPad X230
    ########### Kernel: 6.1.0-20230601
    ############# Uptime: 1 day, 5 hours, 16 mins
    ############### Packages: 2175
    ################ Shell: bash 4.4.20
    ################# Resolution: 1920x1080
    ##################### DE: Unity:Unity7:ubuntu
    ##################### WM: Compiz
    ################# WM Theme: Adwaita
    Theme: Ambiance [GTK2/3]
    Icons: Ubuntu-mono-dark [GTK2/3]
    Terminal: gnome-terminal
    CPU: Intel i7-3615QE (8) @ 3.300GHz
    GPU: Intel HD Graphics 4000
    Memory: 2472MiB / 15576MiB
    xshell
        13
    xshell  
       2023-06-30 08:26:13 +08:00
    root@debian12:~# pkexec echo x; echo $?;
    x
    0
    sunnysab
        14
    sunnysab  
       2023-06-30 08:43:49 +08:00
    [sunnysab@archlinux ~]$ pkexec echo x; echo $?;
    x
    0

    执行前弹出了密码输入框。
    wozhidaole
        15
    wozhidaole  
       2023-06-30 08:58:44 +08:00
    [root@VM-4-10-centos ~]# pkexec echo x; echo $?;
    x
    0
    [root@VM-4-10-centos ~]# uname -a
    Linux VM-4-10-centos 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
    [root@VM-4-10-centos ~]#
    luozic
        16
    luozic  
       2023-06-30 09:11:34 +08:00
    ubuntu23.04
    Ubuntu@ubuntu:~$ pkexec echo x; echo $?;
    x
    0
    fhy1994
        17
    fhy1994  
       2023-06-30 09:30:41 +08:00
    Deepin 20.9

    ```bash
    # f @ f-PC in ~ [9:29:17]
    $ pkexec echo x; echo $?;
    x
    0
    ```
    ecee
        18
    ecee  
       2023-06-30 09:39:01 +08:00
    archlinux, 桌面是 vnc 启动的 xfce ,需要输入 root 密码
    [test@legion ~]$ pkexec echo x; echo$?;
    x
    0
    hokori
        19
    hokori  
       2023-06-30 09:44:22 +08:00
    ubun-virtual-machine ~ » pkexec echo x; echo $?;
    x
    0

    但是需要输入密码
    环境:
    yyyyy- -yyyyyy+ OS: Ubuntu 18.04 bionic
    ://+//////-yyyyyyo Kernel: x86_64 Linux 5.4.0-150-generic
    sxzzsf
        20
    sxzzsf  
       2023-06-30 09:45:29 +08:00
    bash: pkexec: command not found
    127
    ljn917
        21
    ljn917  
       2023-06-30 09:45:33 +08:00 via Android
    ```
    $ pkexec echo x; echo $?;
    x
    0
    ```

    Fedora 37, KDE, 会提示输入 root 密码
    lesteryou
        22
    lesteryou  
       2023-06-30 10:00:52 +08:00
    Deepin 20.9
    Linux Ori-DP 5.17.3-amd64-desktop #1 SMP PREEMPT Fri Apr 29 15:22:29 CST 2022 x86_64 GNU/Linux
    ```
    ~ ⌚ 9:57:42
    $ pkexec echo x; echo $?
    x
    0
    ```
    回车后,弹出密码验证框
    dbskcnc
        23
    dbskcnc  
       2023-06-30 10:25:29 +08:00
    manjaro kde
    pkexec echo x; echo $?
    x
    0
    pkexec echo x; echo $?
    Error executing command as another user: Not authorized

    This incident has been reported.
    127
    zsj1029
        24
    zsj1029  
       2023-06-30 10:26:55 +08:00
    ~ sudo pkexec echo x; echo $?;
    x
    0
    ~ lsb_release -a
    No LSB modules are available.
    Distributor ID: Debian
    Description: Debian GNU/Linux trixie/sid
    Release: n/a
    Codename: trixie
    Debian 12
    kgcHQbTYyvcz2w3j
        25
    kgcHQbTYyvcz2w3j  
       2023-06-30 10:33:42 +08:00
    Arch Linux 6.3.8-arch1-1 直接 x11 套 awesome wm , 加不加 sudo 有两种结果

    $ pkexec echo x; echo $?;
    x
    0

    $ sudo pkexec echo x; echo $?;
    ==== AUTHENTICATING FOR org.freedesktop.policykit.exec ====
    Authentication is needed to run `/usr/bin/echo' as the super user
    Authenticating as: Max (max)
    Password:
    polkit-agent-helper-1: error response to PolicyKit daemon: GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: No session for cookie
    ==== AUTHENTICATION FAILED ====
    Error executing command as another user: Not authorized

    This incident has been reported.
    127
    kokutou
        26
    kokutou  
       2023-06-30 10:40:54 +08:00
    msys2

    ➜ ~ pkexec echo x; echo $?;
    zsh: command not found: pkexec
    127
    ➜ ~
    leehomyhh
        27
    leehomyhh  
       2023-06-30 10:45:26 +08:00
    [root@dev3430 ~]# pkexec echo x; echo $?;
    x
    0
    Mikewangyankkk
        28
    Mikewangyankkk  
       2023-06-30 10:58:35 +08:00
    [root@ypzflqgbrczsm2nr ~]# neofetch
    ##### [email protected]
    ####### -------------------------------
    ##O#O## OS: Anolis OS 8.8 x86_64
    ####### Host: OpenStack Compute 17.0.3-1.el7
    ########### Kernel: 5.10.134-14.1.an8.x86_64
    ############# Uptime: 22 days, 21 hours, 1 min
    ############### Packages: 823 (rpm)
    ################ Shell: bash 4.4.20
    ################# Resolution: 1024x768
    ##################### Terminal: /dev/pts/0
    ##################### CPU: Intel Xeon (Skylake, IBRS) (2) @ 2.299GHz
    ################# GPU: 00:02.0 Cirrus Logic GD 5446
    Memory: 846MiB / 3725MiB
    [root@ypzflqgbrczsm2nr ~]# pkexec echo x; echo $?;
    x
    0
    xiaofami
        29
    xiaofami  
       2023-06-30 16:45:04 +08:00
    Manjaro ARM:

    [marly@manjaro ~]$ sudo inxi -F
    System:
    Host: manjaro Kernel: 6.3.0-1-MANJARO-ARM-ODROID arch: aarch64 bits: 64 Console: pty pts/1
    Distro: Manjaro ARM
    Machine:
    Type: ARM System: Amlogic Meson GXBB P201 Development Board details: N/A
    CPU:
    Info: quad core model: N/A variant: cortex-a53 bits: 64 type: MCP
    Speed (MHz): avg: 2016 min/max: 100/2016 cores: 1: 2016 2: 2016 3: 2016 4: 2016
    Graphics:
    Device-1: meson-gxbb-dw-hdmi driver: meson_dw_hdmi v: N/A
    Device-2: meson-gxbb-vpu driver: meson_drm v: N/A
    Device-3: meson-gxbb-mali driver: lima v: kernel
    Display: server: Xwayland v: 23.1.1 driver: N/A tty: 179x49
    API: EGL/GBM Message: No known Wayland EGL/GBM data sources.
    Audio:
    Device-1: meson-gxbb-dw-hdmi driver: meson_dw_hdmi
    API: ALSA v: k6.3.0-1-MANJARO-ARM-ODROID status: kernel-api
    Network:
    Device-1: meson-gxbb-dwmac driver: meson8b_dwmac
    IF: eth0 state: up speed: 100 Mbps duplex: full mac: 2e:a9:49:75:91:71
    Device-2: pwm-clock driver: pwm_clock
    IF-ID-1: ip6tnl0 state: down mac: 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
    Drives:
    Local Storage: total: 123.02 GiB used: 14.85 GiB (12.1%)
    ID-1: /dev/mmcblk0 model: ED2S5 size: 119.38 GiB
    ID-2: /dev/mmcblk1 model: 4FPD3R size: 3.64 GiB
    Partition:
    ID-1: / size: 116.99 GiB used: 14.79 GiB (12.6%) fs: ext4 dev: /dev/mmcblk0p2
    ID-2: /boot size: 457.5 MiB used: 53.8 MiB (11.8%) fs: vfat dev: /dev/mmcblk0p1
    Swap:
    Alert: No swap data was found.
    Sensors:
    Src: lm-sensors+/sys Message: No sensor data found using /sys/class/hwmon or lm-sensors.
    Info:
    Processes: 158 Uptime: 18d 8h 21m Memory: available: 922.9 MiB used: 474.8 MiB (51.4%)
    Init: systemd Shell: Bash inxi: 3.3.27


    [marly@manjaro ~]$ pkexec echo x; echo $?;
    ==== AUTHENTICATING FOR org.freedesktop.policykit.exec ====
    Authentication is needed to run `/usr/bin/echo' as the super user
    Authenticating as: marly
    Password:
    polkit-agent-helper-1: error response to PolicyKit daemon: GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: No session for cookie
    ==== AUTHENTICATION FAILED ====
    Error executing command as another user: Not authorized

    This incident has been reported.
    127
    [marly@manjaro ~]$ sudo pkexec echo x; echo $?;
    x
    0
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2609 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 10:33 · PVG 18:33 · LAX 02:33 · JFK 05:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.