Find the Process on a Port
sudo lsof -i :80Run it with sudo; without root, lsof shows only your own processes. Each line is one open connection or listening socket:
| Column | Meaning |
|---|---|
| COMMAND | Program name. |
| PID | Process ID. |
| USER | Account it runs as. |
| FD | File descriptor number. |
| NAME | Address, port, and state. |
A web server usually shows several lines, one for the main process and one per worker. If the command prints nothing, no process uses the port.
Install lsof
Minimal server images often leave it out:
sudo apt install lsof # Debian and Ubuntu
sudo dnf install lsof # AlmaLinux and Rocky LinuxShow Only Listening Ports
sudo lsof -iTCP -sTCP:LISTEN -P -n
sudo lsof -iTCP:443 -sTCP:LISTEN -P -n-sTCP:LISTEN hides established connections. -P prints port numbers instead of names such as "https", and -n skips DNS lookups, which makes the command much faster on a busy server.
Network Filters
| Option | Shows |
|---|---|
-i tcp | All TCP sockets. |
-i udp | All UDP sockets. |
-i :22 | Port 22, TCP and UDP. |
-i tcp:3306 | TCP port 3306 only. |
-i4 | IPv4 sockets only. |
Files by User, PID, or Program
sudo lsof -u deploy
sudo lsof -p 12345
sudo lsof -c nginx
sudo lsof -a -u deploy -iBy default, lsof combines several options with OR. -a switches to AND, so the last line shows network connections of the user deploy only. Add -t to print bare PIDs, which is useful in scripts.
What Keeps a Disk Busy
If umount fails with "target is busy", list what is open on that mount:
sudo lsof /mnt/data
sudo fuser -vm /mnt/dataOften it is a shell whose current folder is inside the mount; cd out of it. For a service, stop it with systemctl, then unmount.
Deleted Files That Still Use Space
When a program keeps a deleted file open, the space is not freed until the program closes it. This is why df can show a full disk after you removed a large log:
sudo lsof +L1The output lists those files with the program and PID. Restart that service, for example sudo systemctl restart nginx, and the space comes back. More on this in how to check disk space in Linux.
ss: the Faster Alternative for Ports
sudo ss -ltnp
sudo ss -ltnp 'sport = :80'ss is installed on every current distribution. -l lists listening sockets, -t TCP (use -u for UDP), -n numbers, and -p the process. The process name and PID appear in the last column. Other everyday tools are in Linux network commands.
Fix "Address Already in Use"
- Find the process:
sudo lsof -i :8080 -P -n. - If it is a service you know, stop or reconfigure it with systemctl.
- If it is an old copy of your own program, end it with
kill PIDand check again; usekill -9only if it does not exit. - Otherwise, choose another port for the new program.
Before you change the port of SSH itself, read how to change the SSH port. To match a PID to a full command line, see how to list running processes.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations