Search code examples
dockermacosport

Can I kill existing processes running on port 22 on mac


I want to open port 22 of my mac to run a docker container. Is it safe to kill processes running on port 22 on mac.

My mac has below ports running. Will there be any repercussion of killing these PIDs

COMMAND PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
launchd   1 root    8u  IPv6 0x143bad02273a750d      0t0  TCP *:ssh (LISTEN)
launchd   1 root    9u  IPv4 0x143bacf3c3c23c6d      0t0  TCP *:ssh (LISTEN)
launchd   1 root   11u  IPv6 0x143bad02273a750d      0t0  TCP *:ssh (LISTEN)
launchd   1 root   12u  IPv4 0x143bacf3c3c23c6d      0t0  TCP *:ssh (LISTEN)

I want to run below docker command:

docker run -it --name new_ubutu_ssh_container -p 22:22 ubuntu_ssh:23.04

I am not able to kill the processes getting below error

sudo kill -9 1    
kill: 1: Operation not permitted

Solution

  • launchd at process ID #1 is the master process that starts and monitors pretty much all other processes in macOS. It's probably System Integrity Protection (SIP) that's preventing you from killing it, because killing it would severely damage macOS' ability to function. I'm not sure if you'd get a reboot, a kernel panic, or just a degraded-but-running system (and I'm not going to override SIP to find out).

    It'd be much better to either use an alternate port for ssh in your docker container, or to tell launchd to stop listening for ssh connections in System Preferences -> Sharing pane -> turn off the Remote Login (aka ssh) service.