SSH认证支持sudo

This commit is contained in:
GoEdgeLab
2021-12-06 19:27:11 +08:00
parent 97b34024c1
commit 48f7fc03cb
14 changed files with 382 additions and 130 deletions

View File

@@ -97,6 +97,12 @@ func (this *NodeInstaller) Install(dir string, params interface{}, installStatus
// 修改配置文件
{
configFile := dir + "/edge-node/configs/api.yaml"
// sudo之后我们需要修改配置目录才能写入文件
if this.client.sudo {
_, _, _ = this.client.Exec("chown " + this.client.User() + " " + filepath.Dir(configFile))
}
var data = []byte(`rpc:
endpoints: [ ${endpoints} ]
nodeId: "${nodeId}"
@@ -108,7 +114,7 @@ secret: "${nodeSecret}"`)
_, err = this.client.WriteFile(configFile, data)
if err != nil {
return errors.New("write 'configs/api.yaml': " + err.Error())
return errors.New("write '" + configFile + "': " + err.Error())
}
}