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.
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 withoutsudoand get this error, are you also running it as root (or some other user) via some other means?sudo scp -r -i ~/path_to_pem_file/pem_file.pem some_directory -o IdentitiesOnly=yes [email protected]:~