![使用 sudo 用户通过 ssh 执行远程命令时出错](https://linux22.com/image/1479677/%E4%BD%BF%E7%94%A8%20sudo%20%E7%94%A8%E6%88%B7%E9%80%9A%E8%BF%87%20ssh%20%E6%89%A7%E8%A1%8C%E8%BF%9C%E7%A8%8B%E5%91%BD%E4%BB%A4%E6%97%B6%E5%87%BA%E9%94%99.png)
以下命令失败:
ssh -t user@server-01 sudo -iu suser "cd /opt/jboss ; ./portal.sh stop"
我得到:
bash: ./portal.sh: No such file or directory
如何远程更改目录并在该目录中执行远程命令?
答案1
解决方案是:
ssh -t user@server-01 sudo -iu suser "eval 'cd /opt/jboss ; ./portal.sh stop'"