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.

Marlo
  • 105
  • 6
  • Have you tried the FQDN? – Zac67 Jul 25 '21 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? – Gordon Davisson Jul 25 '21 at 19:17
  • @Zac67: What is FQDN? – Marlo Jul 27 '21 at 00:58
  • @Gordon Davisson: I will try this tomorrow. I think this is the issue. – Marlo Jul 27 '21 at 00: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 ubuntu@ec2-x-xxx-xx-xxx.eu-central-1.compute.amazonaws.com:~` – Gordon Davisson Jul 27 '21 at 03:22

0 Answers0