Lsof : command not found while ssh and running a script

Getting error “lsof: command not found” via ssh from “appleboy/ssh-action@master” using a script “” in aws ec2 from github action.

Action Script
name: Start Service
uses: appleboy/ssh-action@master
host: ${{ secrets.AWS_SSH_HOST_DEV }}
username: ${{ secrets.AWS_SSH_USER_DEV }}
key: ${{ secrets.AWS_SSH_KEY_DEV }}
port: 22
script: |


This is a deployment script

cd /home/work
echo “Entering $(pwd)”

echo “Kill java application process on 8080”
sudo kill -9 $(lsof -t -i:8080)

echo “Run java application with properties”
nohup java -jar abc.jar > out.log &

echo “Deployment Task Successful”

Error Log



out: Entering /home/work

out: Kill java application process on 8080

err: ./ line 8: lsof: command not found

err: kill: not enough arguments

out: Run java application with properties

out: Deployment Task Successful

Screenshot for reference

lsof is a tool to check open files. Apparently the script uses it, or rather tries to, but it’s not installed on the machine you are deploying to. Depending on your use case you either need to install lsof on the machine, or rewrite the script to work without it.

Well whenever I logged into the aws ec2 machine with the same user on github action and run it’s working fine so that means it’s installed in the aws ec2 machine and also installed it in the github action runner machine.
Still it’s not working.

It could also mean lsof is called only under specific circumstances. Or that the PATH is different. Possibly other things. You’ll probably have to take a closer look at the post deploy script to figure that out.

thanks airtower-luna for the help I’ll update after I figured it out till then I’m open for suggestions.

What you’re doing isn’t equivalent to what the workfllow is doing.

because you’re doing ssh ec2-machine (and you didn’t specify a command to run), your ssh client is asking for a login shell and a tty and stuff.

The equivalent would be:

ssh ec2-machine ./

You might need to ask for ssh -tt ...

Here’s a thread that kinda talks about it: