Skip to main content

Kill Port On Ubuntu

· 2 min read
Sivabharathy

To free up a port that is currently being used by a process on Ubuntu, you need to identify the process and then terminate it. Here's how you can do that:

  1. Identify the process using the port: Use the lsof or netstat command to find the process ID (PID) of the process using the port. For example, to check port 3000:

    sudo lsof -i :3000

    Or using netstat:

    sudo netstat -tuln | grep :3000
  2. Find the PID: The output of lsof will look something like this:

    COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    node 12345 user 22u IPv4 123456 0t0 TCP *:3000 (LISTEN)

    Note the PID of the process (in this example, 12345).

  3. Kill the process: Use the kill command to terminate the process using its PID. For example:

    sudo kill -9 12345

    Replace 12345 with the actual PID from the previous step. The -9 option sends a SIGKILL signal, which forces the process to terminate immediately.

Alternative Method: Using fuser

You can also use the fuser command to find and kill the process using a specific port:

  1. Find the PID with fuser:

    sudo fuser -k 3000/tcp

    This command finds the process using port 3000 and sends a SIGKILL signal to terminate it. The -k option kills the process.

Summary

  • Use lsof or netstat to find the PID of the process using the port.
  • Terminate the process using the kill command with the PID.
  • Alternatively, use fuser to find and kill the process in one step.

These methods will help you free up the port on your Ubuntu system.