0

I have a bash script

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

which I made executable with chmod u+x. The remote_host has been defined in my .ssh/config as follows:

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 

when I call scp -r some_directory remote_host:~ or ssh remote_host it works without problems to access the remote machine via ssh. However inside the bash script it doesn't work. I get the following error:

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 

irrespective of whether I sudo the execution of the script or not.

5
  • Have you tried the FQDN? Commented Jul 25, 2021 at 17:22
  • 2
    When you run the script with sudo, it's running as root and hence will look in root's ~/.ssh/config file, not yours; if that doesn't have an entry for remote_host, you'll get this result. When you use the script without sudo and get this error, are you also running it as root (or some other user) via some other means? Commented Jul 25, 2021 at 19:17
  • @Zac67: What is FQDN? Commented Jul 27, 2021 at 0:58
  • @Gordon Davisson: I will try this tomorrow. I think this is the issue. Commented Jul 27, 2021 at 0:59
  • @Marlo FQDN = Fully Qualified Domain Name, i.e. ec2-x-xxx-xx-xxx.eu-central-1.compute.amazonaws.com. That is, have you tried sudo scp -r -i ~/path_to_pem_file/pem_file.pem some_directory -o IdentitiesOnly=yes [email protected]:~ Commented Jul 27, 2021 at 3:22

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.