首页 > 解决方案 > 如何在 python 中为 tarfile 模块设置 root 权限?

问题描述

这是我的代码:

gitlab_restore = tarfile.open("PATH/gitconf.tar")
gitlab_restore.extract("/opt/destination/path")
gitlab_restore.close()

当我运行它时发生了这个错误

2021-11-07 09:44:37,139 - root - ERROR - [Errno 13] Permission denied: '/opt/destination/path'

如何设置 tarfile 模块的 root 权限以在 /opt 上写入?

标签: pythonextractroottartarfile

解决方案


你不能。相反,运行脚本的用户应该具有 root 权限。在你的例子中是这样的:

sudo python my_extractor.py


推荐阅读