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

315 天前
 opentrade

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

pkexec echo x; echo $?;
3354 次点击
所在节点    程序员
29 条回复
churchmice
315 天前
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
315 天前
ubuntu22.04
需要输入密码运行这个命令,运行后得到输出
x
0
coolfan
315 天前
Ubuntu 22.04.2 LTS on Windows 10 x86_64

****@LAPTOP-Fan:~$ sudo pkexec echo x; echo $?;
[sudo] password for ****:
x
0
GeruzoniAnsasu
315 天前
我遇到了跟这个问题完全一致的现象:

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

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


sudo pkexec 正常
prosixe
315 天前
Error executing command as another user: Request dismissed
126
Ubuntu 23.04
bjzhush
315 天前
➜ ~ 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
315 天前
oIMOo
315 天前
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
315 天前
```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
315 天前
❯ 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
315 天前
支持楼主开发桌面 app.

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

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

https://wiki.archlinux.org/title/Polkit
0superx0
315 天前
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
314 天前
root@debian12:~# pkexec echo x; echo $?;
x
0
sunnysab
314 天前
[sunnysab@archlinux ~]$ pkexec echo x; echo $?;
x
0

执行前弹出了密码输入框。
wozhidaole
314 天前
[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
314 天前
ubuntu23.04
Ubuntu@ubuntu:~$ pkexec echo x; echo $?;
x
0
fhy1994
314 天前
Deepin 20.9

```bash
# f @ f-PC in ~ [9:29:17]
$ pkexec echo x; echo $?;
x
0
```
ecee
314 天前
archlinux, 桌面是 vnc 启动的 xfce ,需要输入 root 密码
[test@legion ~]$ pkexec echo x; echo$?;
x
0
hokori
314 天前
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
314 天前
bash: pkexec: command not found
127

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/952838

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX