Skip to main content

Run remote commands on EC2

·1 min

Fire and forget:

scp -i ~/.ssh/key.pem file.sh ec2-user@$PUBLIC_IP:~
ssh -i ~/.ssh/key.pem ec2-user@$PUBLIC_IP " \
    sh -c 'nohup ~/file.sh > /dev/null 2>&1 &' \
"

Or:

ssh -i ~/.ssh/key.pem ec2-user@$PUBLIC_IP "sudo shutdown now > /dev/null 2>&1 &"