從 bash 腳本中呼叫時,ssh 代理程式無法“解析主機名稱”

從 bash 腳本中呼叫時,ssh 代理程式無法“解析主機名稱”

我有一個 bash 腳本

#!/bin/bash
scp -r some_directory remote_host:~

我用它製作了可執行檔chmod u+x。 Remote_host 已在我的 .ssh/config 中定義如下:

Host remote_host
HostName ec2-x-xxx-xx-xxx.eu-central-1.compute.amazonaws.com
User ubuntu
IdentityFile ~/path_to_pem_file/pem_file.pem
IdentitiesOnly yes

當我打電話scp -r some_directory remote_host:~ssh remote_host透過 ssh 存取遠端電腦時沒有問題。但是在 bash 腳本中它不起作用。我收到以下錯誤:

ssh: Could not resolve hostname mochacle: Name or service not known
lost connection
ssh: Could not resolve hostname mochacle: Name or service not known
ssh: Could not resolve hostname mochacle: Name or service not known

無論我是否 sudo 執行腳本。

相關內容