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

SSHBEGINNERHIGHUpdated Jan 4, 2026ยท 272 views

The SSH daemon (sshd) cannot bind to port 22 because another process is already using it, or a previous sshd instance hasn't fully released the port. This error specifically indicates an IPv6 binding conflict (the :: address) and occurs during server startup.

Quick fix

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

sudo lsof -i :22
# or
sudo netstat -tulpn | grep :22
# or (modern systems)
sudo ss -tulpn | grep :22
  1. Check what process is using port 22
  2. Stop conflicting sshd processes
  3. Disable socket activation conflict (systemd)
  4. Review sshd_config ListenAddress configuration
ssh โ€” error
sudo lsof -i :22
# or
sudo netstat -tulpn | grep :22
# or (modern systems)
sudo ss -tulpn | grep :22
error: Bind to port 22 on :: failed: Address already in use.

What this error means

When sshd starts, it attempts to bind to configured listening ports. If a port is already in use by another process, or if a previous instance of sshd hasn't completely terminated and released the socket (which can take 60 seconds due to TIME_WAIT state), the startup fails. The :: notation represents the IPv6 unspecified address, indicating this particular binding attempt is for IPv6 on port 22. This error prevents the SSH daemon from starting, making remote access via SSH impossible.

Typical symptoms

  • SSH server fails to start or restart with 'Address already in use' error
  • Cannot SSH into the server after a service restart attempt
  • Error message includes 'Bind to port 22 on :: failed'
  • SSH service shows as failed or inactive when you check systemctl status
  • Multiple sshd processes visible when checking ps aux
  • Port 22 appears in use when you run netstat/ss commands

Common causes

  1. Another sshd instance is still running from a previous start attempt (not fully terminated)
  2. A different service or process is bound to port 22 (rare on standard Linux servers)
  3. Previous sshd process in TIME_WAIT state (takes up to 60 seconds to release)
  4. Systemd socket activation conflicting with sshd service (socket and service both trying to bind)
  5. IPv6 binding issue where IPv6 socket is listening on both IPv4 and IPv6 without SO_V6ONLY flag
  6. SSH configuration specifies both ListenAddress directives and socket activation is also configured
  7. Permission issue preventing sshd from binding to privileged port 22 (requires root)

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

1Check what process is using port 22

Use one of these commands to identify what's bound to port 22:

bash
sudo lsof -i :22
# or
sudo netstat -tulpn | grep :22
# or (modern systems)
sudo ss -tulpn | grep :22

Output will show the process name and PID. If you see sshd, note the PID for the next step.

2Stop conflicting sshd processes

If multiple sshd instances are running, stop them with:

bash
sudo systemctl stop sshd
# or on some systems
sudo systemctl stop ssh

# Force kill any remaining processes (be careful!)
sudo killall sshd

Wait 10-15 seconds for TIME_WAIT state to clear, then proceed to restart.

3Disable socket activation conflict (systemd)

On systems using systemd socket activation, the ssh.socket might be competing with sshd for the port. Check if this is active:

bash
sudo systemctl status ssh.socket
sudo systemctl status sshd.socket

If active, disable it:

bash
sudo systemctl stop ssh.socket
sudo systemctl disable ssh.socket
sudo systemctl stop sshd.socket
sudo systemctl disable sshd.socket

Then restart just the service:

bash
sudo systemctl restart sshd
# or
sudo systemctl restart ssh
4Review sshd_config ListenAddress configuration

Check your SSH configuration for duplicate or conflicting listen addresses:

bash
sudo grep -n ListenAddress /etc/ssh/sshd_config

Common configurations:
- Listen on both IPv4 and IPv6 (default):

bash
ListenAddress 0.0.0.0
  ListenAddress ::

- Listen on IPv4 only:

bash
ListenAddress 0.0.0.0
  # Comment out: # ListenAddress ::

- Listen on IPv6 only:

bash
ListenAddress ::
  # Comment out: # ListenAddress 0.0.0.0

If you have conflicting entries or custom ports, ensure they're consistent. After editing, validate with:

bash
sudo sshd -t
5Restart sshd and verify

After making changes, restart the SSH service:

bash
sudo systemctl restart sshd

Check that it started successfully:

bash
sudo systemctl status sshd

Verify the port is listening:

bash
sudo ss -tulpn | grep :22

You should see sshd listening on both 0.0.0.0:22 (IPv4) and [::]:22 (IPv6), or whichever you configured.

6Verify SSH connectivity

Test SSH connectivity from another machine:

bash
ssh -v user@hostname.example.com

The -v flag shows verbose output if there are any issues. If connection succeeds, the error is resolved.

For local testing without a second machine:

bash
ssh localhost

Advanced notes

Advanced troubleshooting:

IPv6 Socket Behavior: On most Linux systems, if you bind to :: (IPv6 unspecified address) without the IPV6_V6ONLY socket option set, the IPv6 socket will also accept IPv4 connections. Check with cat /proc/sys/net/ipv6/conf/default/bindv6only (value 1 means IPv6-only, 0 means dual-stack). This should not normally cause conflicts, but can be an issue in edge cases.

TIME_WAIT and SO_REUSEADDR: Normally, the kernel holds a socket in TIME_WAIT state for 60 seconds after closure to prevent port reuse confusion. You can force sshd to reuse the port by setting SO_REUSEADDR, which modern OpenSSH does by default. If you're still getting errors after systemctl stop, wait 60+ seconds or restart the entire system.

Non-standard Ports: If you need to run SSH on a non-standard port (e.g., 2222), change the Port directive in sshd_config instead of using ListenAddress. Some cloud platforms or firewalls may block non-standard SSH ports.

Container/VM Specific: In Docker containers or VMs, the error might indicate the parent host already has sshd on port 22. Verify which port you're actually exposing. In Docker: use -p 2222:22 to expose the container's port 22 as 2222 on the host.

Debugging: Run sshd in debug mode before fully restarting:

bash
sudo sshd -D -d

This runs sshd in foreground with debug output, showing exactly where it fails to bind.

Frequently asked questions

What does "error: Bind to port 22 on :: failed: Address already in use." mean?
When sshd starts, it attempts to bind to configured listening ports. If a port is already in use by another process, or if a previous instance of sshd hasn't completely terminated and released the socket (which can take 60 seconds due to TIME_WAIT state), the startup fails. The :: notation represents the IPv6 unspecified address, indicating this particular binding attempt is for IPv6 on port 22.
How do I fix "error: Bind to port 22 on :: failed: Address already in use."?
The SSH daemon (sshd) cannot bind to port 22 because another process is already using it, or a previous sshd instance hasn't fully released the port. This error specifically indicates an IPv6 binding conflict (the :: address) and occurs during server startup.
What causes "error: Bind to port 22 on :: failed: Address already in use."?
Another sshd instance is still running from a previous start attempt (not fully terminated) A different service or process is bound to port 22 (rare on standard Linux servers) Previous sshd process in TIME_WAIT state (takes up to 60 seconds to release)
Is the "error: Bind to port 22 on :: 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