【问题标题】:fabric sudo permission denied面料 sudo 权限被拒绝
【发布时间】:2014-12-11 10:40:31
【问题描述】:

设置:

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

问题:当我尝试在“/opt/”下创建文件夹时,它返回“Permission denied”。

来自我的 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/"

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

有没有更好的解决方案?我错过了什么吗?

【问题讨论】:

    标签: python sudo fabric


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2022-01-03
      • 2017-03-01
      • 2015-03-19
      • 2021-12-11
      • 1970-01-01
      • 1970-01-01
      • 2016-11-12
      • 1970-01-01
      • 2015-08-30
      相关资源
      最近更新 更多