lsof (list open files) shows which process holds a file or a port. Perfect when a service fails to start because the port is already taken.
Steps
Install lsof:
sudo apt updatesudo apt install -y lsofWho is listening on port 80?
sudo lsof -iTCP:80 -sTCP:LISTENWhich files does a given PID have open?
sudo lsof -p PIDWhich process has a path open (e.g. a log or socket):
sudo lsof /var/log/syslog
Tips
- Without
sudoyou only see your own processes; on servers use root. - To free a port: note the PID from lsof, then
kill PIDcarefully.
ext step
Debug ports on your own VPS: Deploy your Cloud VPS.