How to fix error: Bind to port 22 on 0.0.0.0 failed: Address already in use. in SSH

SSHINTERMEDIATEHIGHUpdated Jan 4, 2026· 301 views

This error occurs when the SSH daemon (sshd) cannot bind to port 22 because another process is already listening on it. Common causes include duplicate sshd instances, IPv6/IPv4 binding conflicts, or configuration issues.

Quick fix

Fixes error: Bind to port 22 on 0.0.0.0 failed: Address already in use.

sudo lsof -i :22
  1. Check what process is using port 22
  2. Stop the existing SSH service
  3. Kill any remaining SSH processes
  4. Check sshd_config for conflicting ListenAddress directives
ssh — error
sudo lsof -i :22
error: Bind to port 22 on 0.0.0.0 failed: Address already in use.

What this error means

The SSH daemon (sshd) attempted to start and bind to port 22, which is the standard port for SSH connections. However, the operating system rejected this request because port 22 is already in use by another process. This typically means either another sshd instance is running, or a different service has claimed the port. Port binding conflicts prevent the new service from accepting incoming connections on that port.

Typical symptoms

  • SSH service fails to start when running 'systemctl start sshd'
  • Manual sshd startup produces the 'Address already in use' error message
  • SSH connections timeout or refuse to connect
  • Previous SSH sessions continue working but new connections fail
  • After system reboot, SSH service fails to start automatically

Common causes

  1. Another sshd process is still running from a previous session or failed restart
  2. IPv6 and IPv4 dual-stack binding conflict where the IPv6 socket on :: is also accepting IPv4 connections
  3. sshd_config has multiple conflicting ListenAddress directives for the same port
  4. Kernel parameter net.ipv6.bindv6only is set to 0, causing IPv6 socket to claim port for both IPv4 and IPv6
  5. A different service or application has bound to port 22
  6. Port 22 is being held in TIME_WAIT state from a recent connection

How to fix "error: Bind to port 22 on 0.0.0.0 failed: Address already in use."

1Check what process is using port 22

First, identify which process currently holds port 22. Use one of these commands:

bash
sudo lsof -i :22

Or with netstat:

bash
sudo netstat -tulpn | grep :22

Or with ss (modern systems):

bash
sudo ss -tulpn | grep :22

The output will show the process name and PID. If it shows sshd is already running, you likely have a duplicate process. If it's a different service, note that name.

2Stop the existing SSH service

Stop the currently running SSH service gracefully:

bash
sudo systemctl stop sshd

Or on older systems:

bash
sudo service ssh stop

Wait a few seconds for the process to terminate. If it doesn't stop cleanly, check the next step.

3Kill any remaining SSH processes

If the service didn't stop cleanly, forcefully terminate the process:

bash
sudo fuser -k 22/tcp

Or using the PID from your earlier lsof/netstat output:

bash
sudo kill -9 <PID>

Verify the port is now free:

bash
sudo lsof -i :22

This should return no results.

4Check sshd_config for conflicting ListenAddress directives

Review your SSH configuration for issues:

bash
sudo grep -n "ListenAddress\|Port" /etc/ssh/sshd_config | grep -v "^#"

Look for:
- Multiple Port directives on the same line or repeated
- Multiple ListenAddress entries that could conflict
- ListenAddress directives pointing to non-existent IP addresses

If you find duplicates or invalid addresses, comment them out:

bash
sudo nano /etc/ssh/sshd_config

For a basic setup, use just:

bash
Port 22
ListenAddress 0.0.0.0
ListenAddress ::
5Test the configuration before restarting

Always test your sshd configuration for syntax errors before restarting:

bash
sudo sshd -t

If no output appears, the configuration is valid. If errors appear, fix them and repeat this test.

You can also do a dry-run start:

bash
sudo sshd -t -D

This will attempt to bind to ports but won't daemonize.

6Restart the SSH service

Once configuration is validated and port 22 is free, restart sshd:

bash
sudo systemctl start sshd

Or:

bash
sudo service ssh start

Verify it's running:

bash
sudo systemctl status sshd

You should see "active (running)" in the output.

7Test SSH connectivity

Test that SSH is now accepting connections:

bash
ssh -v localhost

Or from a remote machine:

bash
ssh user@your-server-ip

If the connection succeeds, the issue is resolved.

Advanced notes

IPv6/IPv4 Dual-Stack Binding: By default, if sshd binds to the IPv6 address :: (all interfaces) with the net.ipv6.bindv6only kernel parameter set to 0 (the default), the IPv6 socket automatically accepts both IPv6 and IPv4 connections. This prevents a subsequent attempt to bind to 0.0.0.0 (IPv4 all interfaces). To resolve this, either: (1) Explicitly set ListenAddress 0.0.0.0 and ListenAddress :: to force separate sockets, or (2) Change the kernel parameter with 'sysctl -w net.ipv6.bindv6only=1', or (3) Disable IPv6 in sshd_config with ListenAddress 0.0.0.0 only. Alternative Port: If port 22 is reserved by another critical service, you can change SSH to run on an alternative port (e.g., 2222) by modifying Port in sshd_config. Remember to update firewall rules and document this change. TIME_WAIT State: On some systems, sockets remain in TIME_WAIT for 60 seconds after closure. If you just restarted sshd, wait a moment before checking if the port is truly free. Use 'ss -tpn' to see socket states.

Frequently asked questions

What does "error: Bind to port 22 on 0.0.0.0 failed: Address already in use." mean?
The SSH daemon (sshd) attempted to start and bind to port 22, which is the standard port for SSH connections. However, the operating system rejected this request because port 22 is already in use by another process. This typically means either another sshd instance is running, or a different service has claimed the port.
How do I fix "error: Bind to port 22 on 0.0.0.0 failed: Address already in use."?
This error occurs when the SSH daemon (sshd) cannot bind to port 22 because another process is already listening on it. Common causes include duplicate sshd instances, IPv6/IPv4 binding conflicts, or configuration issues.
What causes "error: Bind to port 22 on 0.0.0.0 failed: Address already in use."?
Another sshd process is still running from a previous session or failed restart IPv6 and IPv4 dual-stack binding conflict where the IPv6 socket on :: is also accepting IPv4 connections sshd_config has multiple conflicting ListenAddress directives for the same port
Is the "error: Bind to port 22 on 0.0.0.0 failed: Address already in use." error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading