SSHエージェントは、bashスクリプト内から呼び出されると「ホスト名を解決」できません

SSHエージェントは、bashスクリプト内から呼び出されると「ホスト名を解決」できません

私は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_hostssh 経由でリモート マシンにアクセスするのには問題なく動作します。ただし、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 するかどうかに関係なく。

関連情報