linux - 命令不会在 sudo 之后作为另一个用户回显

标签 linux bash ssh terminal

我有一个命令可以通过 ssh 连接到远程 linux 主机并执行 shell 脚本。 ssh -t -t $USER@somehost 'bash -s' < ./deploy.sh

内部deploy.sh我有这个:

#!/bin/bash

whoami;                 # I see this command echo
sudo -i -u someoneelse  #I see this command echo
whoami;                 # I DON'T see this command echo, but response is correct

#subsequent commands don't echo

当我运行 deploy.sh在本地编写所有命令回显的脚本。

在我作为另一个用户通过 ssh 执行 sudo 后,如何让命令回显?

最佳答案

必须 set -x AFTER sudo as another user

#!/bin/bash

whoami;
sudo -i -u someonelese
set -x              #make sure echo on
whoami;             #command echoed

关于linux - 命令不会在 sudo 之后作为另一个用户回显,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42952934/

相关文章:

bash - 如何从目录中递归查找所有文件扩展名?

java - 在 jsch ChannelExec 上设置环境变量

bash - ssh 和环境变量 remote 和 local

perl - 如何确定用户是否在 perl 脚本中有 ssh key

su'ing到不同用户后的linux和音频

python - 使用 dos2unix 将 windows 文件转换为 unix 的 shell 脚本

linux - 在 TRichView 上自动滚动(lazarus)

Linux 脚本嵌套的 if 语句给出语法错误

linux - Bash 从匹配特定文本的行的输出中排除一行

linux - 带有括号的 Bash for 循环在 linux 中工作,而不是在 Git Bash 中工作