Skip to content

Instantly share code, notes, and snippets.

@chuckntaylor
Last active April 5, 2024 15:04
Show Gist options
  • Save chuckntaylor/29fee85111d66dfe078b02fc28f56173 to your computer and use it in GitHub Desktop.
Save chuckntaylor/29fee85111d66dfe078b02fc28f56173 to your computer and use it in GitHub Desktop.
Closing a port

How to close a port on Mac

In Terminal, type the following command to find the process ID (PID) of the port. Replace PORT_NUMBER with the actual port number you want to close.

sudo lsof -i :PORT_NUMBER

Copy the PID number, then use the following command to kill the process using the PID you found.

sudo kill PID_NUMBER

To verify that the port has been closed, you can try to connect to the port.

nc localhost PORT_NUMBER

If it returns immediately without any output, the port is closed. If it retruns some input, try killing it with:

sudo kill -9 PID_NUMBER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment