简体   繁体   中英

How to use ssh to run a local .sh file (present on a local linux machine) on a remote linux machine (an AWS ec2 instance)

I am having a tough time figuring out a way to execute a .sh file present on my local linux machine on to a remote linux machine which happens to be an AWS ec2 instance. Here's what I am doing on my local machine:

ssh -i sample.pem ec2-user@server_name.amazon.com 'bash -s' < file_to_remotely_execute.sh

Error that I get is:

Warning: Identity file sample.pem not accessible: No such file or directory. Pseudo-terminal will not be allocated because stdin is not a terminal. Host key verification failed.

This was referred to arrive at the above approach.

Possible issues :

  1. The PEM file doesn't exist.
  2. The PEM file doesn't have proper permissions.
  3. The host is not allowed in ~/.ssh/known_hosts file.

Solutions :

  1. Navigate to the location where PEM file exists or give full path of PEM file.
  2. Give 400 permissions to the PEM file, ( sudo chmod 400 /path/to/file.pem ).
  3. Login to the server by ssh once, and allow the host.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM