我希望能够从Python子进程模块挂载和卸载一个名为sshfs的目录。下面是我用来实现这一点的代码。
import subprocess
mkdir_command = 'mkdir {}'.format(local_data_directory)
unmount_command = 'umount {}'.format(local_data_directory)
mount_command = 'sshfs -o allow_other -o IdentityFile={} {}@{}:{} {}'.format(
key_file, host_username, host_ip, host_data_directory, local_data_directory)
subprocess.call(mkdir_command, shell=True)
subprocess.call(mount_command, shell=True)
subprocess.call(unmount_command, shell=True)mkdir和mount命令是成功的,但是当我尝试卸载目录时,我得到了错误umount失败:不允许操作。我猜这是因为子进程用户对local_data_directory的父文件夹没有写权限。当我检查local_data_directory的权限时,它说所有者是用户#1004。这是Python子进程的默认用户吗?我想我可以只给用户所有父目录的写权限,但我不想给我整个主文件夹的子进程写权限。有没有办法不用这么做就能解决这个问题呢?
https://stackoverflow.com/questions/41316632
复制相似问题