Software developer's home office desk in evening light

Finding the Process Behind an Open Port on Linux

To find the process using a port on Linux, you can run one command, usually ss or lsof. Either tool returns the program’s name and its process ID (PID), which is the number the kernel uses to track that program.

That PID only gets you halfway, though. At Basic Linux, we think fixing the conflict means deciding whether that process should be running at all. Make that check before you stop anything.

This guide covers why ports get stuck, how to read ss output, and when lsof, fuser or netstat suits the job better. You’ll also see what to check once you have the PID, so a restart doesn’t bring the same clash back. Start with the cause.

Why Does a Port Show as Already in Use on Linux?

Technician in a climate-controlled server room standing in front

A port shows as already in use because only one listening socket can hold a given address, port, and protocol at a time. When a second program asks for that same slot, the kernel refuses and the program logs “Address already in use” before it quits.

In practice, the culprit is usually familiar. If you’ve ever installed Nginx on a server that already ran the Apache web server, you’ve seen this, because both default to port 80. An old copy of your own app can cause the same clash. This happens when a crash leaves it running in the background.

Timing plays a part too. After a service stops, its recent connections can sit in a TIME_WAIT state for a short while. An app that doesn’t set the reuse option can then run into problems with those connections. You’ll know you’re facing this case when ss shows TIME_WAIT rows but nothing in the LISTEN state.

That’s why the error message alone won’t tell you which of these causes you’re dealing with. Each one needs a different fix, which is why the next step is putting a name and a PID to whatever holds the port.

Using the ss Command to List Listening Ports and Their PIDs

The ss command (short for socket statistics) ships with the iproute2 package on most modern Linux systems. That includes Debian, Ubuntu, Rocky Linux, and Arch Linux. It replaced the older netstat command and reads socket details straight from the kernel, so it stays quick even on a busy server.

Let’s work through the flags, the columns, a one-port filter, and the permission catch, in that order.

What the -tulpn Flags Tell ss to Show

Each letter in -tulpn switches on one part of the output. TCP and UDP sockets come from -t and -u, and -p adds the process that owns each one. Meanwhile, according to the ss manual page on the listening flag, -l will “display only listening sockets (these are omitted by default).”

Besides these, -n prints port numbers instead of service names. You’ll see :80 rather than :http, which makes searching for a specific port number far more reliable.

Reading the Output: Local Address, State and the Users Column

Every row in the output describes one listening socket. Its Local Address: Port column shows where it listens, so 0.0.0.0:80 covers every IPv4 interface and 127.0.0.1:3306 accepts local connections only.

From there, the State column reads LISTEN for TCP and UNCONN for UDP, since UDP has no connection to track. Both states mean a program holds that port open.

Your answer sits in the Users column, in a format like users:(("nginx",pid=1234,fd=6)). Write down the name and the PID value, because every later check works from those two details.

Narrowing the Search to One Port With a Filter

A full listing on a busy server can run to dozens of lines. Rather than scrolling, add a filter such as sudo ss -tlpn 'sport = :8080' to show only that particular port.

Plenty of admins pipe the output through grep :8080 instead (and that works fine for a quick visual check). Trouble is, grep also matches :80800 or a remote port of 8080.

Use the built-in filter in scripts and anywhere a false match could send you after the wrong process. It checks the local port exactly, which grep can’t promise.

Why You Need sudo on a VPS or Hosting Server to See Every PID

Unless you run it as the root user, ss only shows process details for sockets your own account owns. Other rows still appear, but their Users column sits empty.

In hands-on troubleshooting, that empty column is the usual reason someone decides ss is broken. What’s really happening is that the kernel hides other users’ process details from you.

If a row comes back with no owner on your VPS or dedicated server, run sudo ss -tulpn instead. On shared hosting without sudo, ask your provider’s support team which service holds the port.

Developer seated at a desk in a bright modern office

lsof, fuser and netstat: Three Other Ways to Find the Process

Beyond ss, a few older tools answer the same question from slightly different angles. They earn their place on a minimal cloud image or an old box where one of them is the only option installed.

To decide which one fits your machine, compare what each command needs and returns:

Command Example What it returns Best use
lsof sudo lsof -i :8080 Command, PID, user, and the open network file Checking a port’s listeners and live TCP connections together
fuser sudo fuser 8080/tcp PIDs only Short scripts that just need the number
netstat sudo netstat -tulpn The same columns as ss, in an older layout Older CentOS or Debian servers without iproute2

Of the three, lsof covers the most ground. The lsof manual entry for the -i option notes that with no address given, it lists “all Internet and x.25 (HP-UX) network files.”

Where lsof is the broad tool, fuser is the blunt one. Use fuser -k with caution, because it kills every process on the port without a prompt. Run plain fuser first and check that it shows the correct PID.

Knowing the PID Is Only Half of Linux Port Conflict Troubleshooting

Killing a PID returned by ss or lsof can shut down a database, mail server, or control panel. Other services often rely on these programs. They also use specific ports for a reason. For example, a mail server listens on the standard SMTP port to receive email.

An unfamiliar program using an open port needs closer inspection. Treat it as a security question first, and work through our basic hardening steps for a Linux server once you’ve removed it.

Before you send any kill signal, work through these five checks in order:

  • Identify the Program: Run ps -fp PID to see the program’s full command line and the user who launched it. A root-owned process on a self-managed VPS often belongs to a system service rather than your own app. If the name looks unfamiliar, check it for security vulnerabilities before you remove it.
  • Check for Units: Use systemctl status PID to see whether systemd manages the process as a named service. On a server running Ubuntu using its default systemd setup, a killed unit can restart within seconds and grab the port again. Stop it properly with sudo systemctl disable --now servicename instead.
  • Move One Service: Change the listen port in one app’s config file if both services need to keep running. For example, you can move Apache to port 8080 and leave Nginx on port 80. Restart the edited service afterwards so it picks up the new port.
  • Kill Gently First: Send a SIGTERM kill PID first, which gives the program a chance to close its files and connections cleanly. Save kill -9 for processes that ignore it, since a forced kill can leave half-written data behind. You’ll need full administrator access through root or sudo to stop processes that other users own.
  • Verify the Port: Re-run sudo ss -tulpn after the fix to confirm nothing else still listens on that port. Then start your service and check its logs for a clean launch. Add these steps to your VPS setup notes so the next clash takes minutes to fix.

Skip the unit check and systemd will bring the old process back on the next reboot. These steps work the same way on KVM VPS plans, cloud servers, and bare metal dedicated servers.

Each one gives you root access to the same Linux tools. On a fully managed VPS, raise a support ticket before you change any system service, because your provider may already manage that port.

System administrator in an older data center with legacy server

Keep These Commands Within Reach

Finding the process using a port on Linux takes one command, but fixing the clash depends on knowing whether that process belongs there. Getting both halves right stops the same error from turning up after your next restart.

Save sudo ss -tulpn and sudo lsof -i :PORT somewhere you’ll see them. Next time a service refuses to start, check where the PID came from before you kill anything.

Basic Linux publishes plain-English guides for people running their own Linux servers. Keep the Basic Linux commands reference open beside your terminal to sort out port clashes and other everyday jobs faster.

Leave a Reply

Your email address will not be published. Required fields are marked *