gpt4 book ai didi

python - Fabric sudo 权限被拒绝

转载 作者:行者123 更新时间:2023-12-01 04:55:44 24 4
gpt4 key购买 nike

设置:

  • 结构 1.9.1
  • 服务器是centOS 7
  • 用户 tester0 具有管理员权限并且位于 sudoers 文件中

问题:当我尝试在“/opt/”下创建文件夹时,它返回“权限被拒绝”。

来 self 的 fabfile.py:

parent_code_dir = '/opt/deploy_dest'
with settings(sudo_user=pt_root_user,warn_only=False):
sudo("ls /opt/") #this works OK with the sudo command
sudo("id") #this works OK with the sudo command
sudo("mkdir -p %s" % parent_code_dir) #this returns the "Permission denied"

在我的终端中,我看到输出:

[192.168.1.108] sudo: ls
[192.168.1.108] out: rh
[192.168.1.108] out:

[192.168.1.108] sudo: id
[192.168.1.108] out: uid=1000(tester0) gid=1000(tester0) groups=1000(tester0),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[192.168.1.108] out:

[192.168.1.108] sudo: mkdir -p /opt/deploy_dest/
[192.168.1.108] out: mkdir: cannot create directory ‘/opt/deploy_dest/’: Permission denied
Fatal error: sudo() received nonzero return code 1 while executing!
Requested: mkdir -p /opt/pt_server/
Executed: sudo -S -p 'sudo password:' -u "tester0" /bin/bash -l -c "mkdir -p /opt/pt_server/"

我能够手动创建相同的文件夹 sudo mkdir -p /opt/deploy_dest以 tester0 身份访问时通过 ssh。然而,当我运行输出 sudo -S -p 'sudo password:' -u "tester0" /bin/bash -l -c "mkdir -p /opt/pt_server/" 时我遇到了同样的错误,所以我想我应该更改结构 sudo_prefix..

有更好的解决办法吗?我错过了什么吗?

最佳答案

这是/opt/文件夹中的权限问题。用户 tester0 不是 root => 他位于具有 root 权限的组wheel中,但是在运行时sudo -u => 作为 tester0 用户访问/opt/,他仅在组中,但该组不允许写入。一种快速解决方案是 chmod g+w /opt/

关于python - Fabric sudo 权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27420843/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com