shell 脚本中 运行 时的 SCP returns 错误

SCP returns error when running in a shell script

如果我在终端中执行相同的命令它会工作,所以如果我在 shell 脚本中执行它它 returns "The file or directory does not exist"。脚本内外命令相同

scp userNoRoot@1**.***.*.***:/remoteFile.tar.gz /destination

完整剧本

echo "---Start---"
scp userNoRoot@1**.***.*.***:/remotefile.tar.gz /destination
echo "---END---"

我拜访了一个JAVA

String[] newExec= {"/script.sh"};

Process process1 = Runtime.getRuntime().exec(newExec);

BufferedReader br1 = new BufferedReader(new InputStreamReader(process1.getInputStream(), "UTF-8"));

String result1 = br1.lines().collect(Collectors.joining("\n"));

我必须在 scp 之后添加“-i ~/.ssh/id_rsa”来识别用户并且它有效。