How can I kill TCP port 16969 in Bash?

I think that:

lsof -i tcp:22 | grep LISTEN | awk '{print $2}' | xargs kill

Should do the trick.

To double check what commands it wants to run before letting it loose add an echo before the kill like this:

lsof -i tcp:22 | grep LISTEN | awk '{print $2}' | xargs echo kill

It'll then list the PIDs that it would ordinarily kill


fuser -k 16969/tcp 

can free that port. This is a useful command that can be used to close ports, whichever it is.


Have you tried using tcpkill?

example:

tcpkill -i eth0 port 21