Running external commands through os/exec under another user

前端 未结 1 1882
误落风尘
误落风尘 2020-12-28 16:46

Using the os/exec package, I want to run an external command on a *nix OS, on behalf of another user (of course go process run under root user of another user w

相关标签:
1条回答
  • 2020-12-28 16:50

    You can add a syscall.Credential struct to Cmd.SysProcAttr

    cmd := exec.Command(command, args...)
    cmd.SysProcAttr = &syscall.SysProcAttr{}
    cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uid, Gid: gid}
    
    0 讨论(0)
提交回复
热议问题