How to fix bind: Address already in use in SSH

SSHINTERMEDIATEMEDIUMUpdated Jun 8, 2026Β· 393 views

This error occurs when SSH (client or daemon) tries to bind to a port that is already in use by another process or service. Fix it by finding the conflicting process and either terminating it, changing the SSH port, or waiting for socket cleanup.

Quick fix

Fixes bind: Address already in use

# Using lsof (shows process name and PID)
sudo lsof -i :22

# Using netstat (older systems)
sudo netstat -tulpn | grep :22

# Using ss (modern replacement for netstat)
sudo ss -tulpn | grep :22
  1. Identify what process is using the port
  2. Stop or kill the conflicting process
  3. Restart SSH service
  4. Handle TIME_WAIT socket state (for address reuse)
ssh β€” error
# Using lsof (shows process name and PID)
sudo lsof -i :22
# Using netstat (older systems)
sudo netstat -tulpn | grep :22
# Using ss (modern replacement for netstat)
sudo ss -tulpn | grep :22
bind: Address already in use

What this error means

The "bind: Address already in use" error means SSH (either the sshd daemon or an SSH client with port forwarding) attempted to bind to a network port and failed because another process already holds that port. On the server side, this typically happens when sshd tries to start but the SSH port (default 22) is already occupied by another SSH daemon instance, a container, or a conflicting service. On the client side, this error appears when using SSH local port forwarding (-L flag) and the local port you specified is already bound by another application. The error indicates a port conflict that prevents SSH from listening on or forwarding through the requested address and port. This is a socket-level error from the operating system, meaning the kernel cannot allocate the requested port to SSH.

Typical symptoms

  • SSH daemon fails to start with "bind: Address already in use" error
  • Port forwarding with ssh -L fails with the bind error
  • Systemd service sshd shows failed status when starting
  • Restarting SSH service fails but previously worked fine
  • Error appears when starting SSH on a non-standard port
  • Local port forwarding worked before but suddenly fails with bind error
  • Multiple SSH instances or processes visible in process list

Common causes

  1. Another SSH daemon (sshd) instance is already running on the same port
  2. A container or VM is listening on port 22 from a previous failed shutdown
  3. Another service (telnet, dropbear, busybox) is using the SSH port
  4. Local port forwarding target port is already in use by another application
  5. Port is in TIME_WAIT state from a recently closed connection, preventing immediate reuse
  6. IPv4 and IPv6 socket binding conflict when ListenAddress is not properly configured
  7. Systemd socket activation is conflicting with direct sshd binding

How to fix "bind: Address already in use"

1Identify what process is using the port

Use lsof or netstat to find which process is bound to the port. For SSH default port 22:

bash
# Using lsof (shows process name and PID)
sudo lsof -i :22

# Using netstat (older systems)
sudo netstat -tulpn | grep :22

# Using ss (modern replacement for netstat)
sudo ss -tulpn | grep :22

The output will show the process name, PID, and which address/port is bound. For example:

bash
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
sshd      123 root    3u  IPv4  12345      0t0  TCP *:22 (LISTEN)
sshd      456 root    4u  IPv6  12346      0t0  TCP *:22 (LISTEN)

If you see multiple sshd processes, you may have duplicate instances. If you see a different service name, that service is conflicting with SSH.

2Stop or kill the conflicting process

Once you identify the conflicting process, stop it gracefully first, then forcefully if needed.

For a duplicate SSH daemon:

bash
# Find all sshd processes
ps aux | grep sshd

# Kill the extra instance by PID (keep the one with lowest PID, usually the parent)
sudo kill -TERM <PID>

# Force kill if it doesn't respond
sudo kill -9 <PID>

For a systemd service:

bash
# Stop the conflicting service (if known)
sudo systemctl stop <service-name>

# Or stop all SSH services
sudo systemctl stop ssh ssh.socket sshd sshd.socket

For other services like telnet or dropbear, identify and stop them similarly:

bash
sudo systemctl stop telnet
sudo systemctl stop dropbear

After stopping the process, verify it's gone:

bash
sudo lsof -i :22
3Restart SSH service

Once the port is free, restart the SSH daemon:

bash
# On systemd systems
sudo systemctl restart ssh
# or
sudo systemctl restart sshd

# On older init systems
sudo service ssh restart
# or
sudo /etc/init.d/ssh restart

Verify that SSH is now running and listening:

bash
sudo lsof -i :22
sudo netstat -tulpn | grep :22

If SSH starts successfully, you should see the sshd process bound to port 22.

4Handle TIME_WAIT socket state (for address reuse)

If the port shows in TIME_WAIT state even after killing all processes, the OS is holding the port closed for a short period to ensure no stray packets arrive. You have two options:

Option 1: Wait 60-120 seconds for TIME_WAIT to expire:

bash
# Check the state
sudo netstat -tulpn | grep :22

# The port will show as TIME_WAIT
tcp        0      0 0.0.0.0:22              0.0.0.0:*               TIME_WAIT

# Wait and try again
sleep 120
sudo systemctl start ssh

Option 2: Enable socket reuse to avoid TIME_WAIT delays (permanent):

bash
# Edit sshd_config to use SO_REUSEADDR
sudo nano /etc/ssh/sshd_config

# Add or uncomment this line:
# AddressFamily any

# Then restart
sudo systemctl restart ssh

Or enable it system-wide (affects all applications):

bash
# Temporary (until reboot)
sudo sysctl -w net.ipv4.tcp_tw_reuse=1

# Permanent (add to /etc/sysctl.conf)
echo "net.ipv4.tcp_tw_reuse = 1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
5Use a different port if port 22 is unavailable

If you cannot free up port 22 or prefer not to wait, configure SSH to use a different port:

bash
# Edit the SSH daemon config
sudo nano /etc/ssh/sshd_config

# Find the line that says "Port 22" and change it
Port 2222

# Save (Ctrl+X, Y, Enter)

Then restart SSH:

bash
sudo systemctl restart ssh

Verify it's listening on the new port:

bash
sudo lsof -i :2222

Now clients must connect using the new port:

bash
ssh -p 2222 user@hostname

This is useful if port 22 is needed by another service permanently.

6Fix IPv4/IPv6 dual-stack conflicts

Some systems have dual-stack IPv4 and IPv6 listening causing conflicts. Check sshd_config for ListenAddress:

bash
sudo grep "ListenAddress" /etc/ssh/sshd_config

If you see both IPv4 and IPv6 addresses for port 22, ensure they don't conflict:

bash
sudo nano /etc/ssh/sshd_config

# Use one of these patterns:
# Option 1: Listen on all addresses (default)
Port 22
# (Remove any ListenAddress lines)

# Option 2: Listen only on IPv4
Port 22
ListenAddress 0.0.0.0

# Option 3: Listen only on IPv6
Port 22
ListenAddress ::

# Option 4: Listen on specific IPs
Port 22
ListenAddress 192.168.1.100
ListenAddress 2001:db8::1

After editing:

bash
sudo systemctl restart ssh
sudo ss -tulpn | grep :22

Advanced notes

For container environments (Docker, Kubernetes), this error often means the host or container already has sshd running or the container port mapping conflicts with an existing host process. In Docker, ensure your container doesn't start multiple SSH daemons and verify the port mapping (-p flag) doesn't conflict. For Kubernetes, check that multiple pod instances aren't trying to claim the same hostPort. In systemd environments, socket activation (sshd.socket vs direct sshd) can cause conflicts if both are enabledβ€”disable one and use the other. For SSH port forwarding specifically (ssh -L), the error means the local port is already bound, so choose an unused port. Use 'netstat -an | grep LISTEN' to see all occupied ports on your system.

Frequently asked questions

What does "bind: Address already in use" mean?
The "bind: Address already in use" error means SSH (either the sshd daemon or an SSH client with port forwarding) attempted to bind to a network port and failed because another process already holds that port. On the server side, this typically happens when sshd tries to start but the SSH port (default 22) is already occupied by another SSH daemon instance, a container, or a conflicting service. On the client side, this error appears when using SSH local port forwarding (-L flag) and the local port you specified is already bound by another application.
How do I fix "bind: Address already in use"?
This error occurs when SSH (client or daemon) tries to bind to a port that is already in use by another process or service. Fix it by finding the conflicting process and either terminating it, changing the SSH port, or waiting for socket cleanup.
What causes "bind: Address already in use"?
Another SSH daemon (sshd) instance is already running on the same port A container or VM is listening on port 22 from a previous failed shutdown Another service (telnet, dropbear, busybox) is using the SSH port
Is the "bind: Address already in use" error serious?
It is a medium-severity error β€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading