设置:
问题:当我尝试在' / opt /'下创建文件夹时它返回"权限被拒绝"。
来自我的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 ..
有更好的解决方案吗?我错过了什么吗?
答案 0 :(得分:2)
这是/ opt /文件夹中的权限问题。
用户tester0不是root =>他在组轮中具有root权限但在运行时
sudo -u =>作为tester0用户访问/ opt /,他只在组中但该组不允许写入。
一个快速的解决方案是chmod g+w /opt/