How to fix error: Bind to port 22 on :: failed: Address already in use. in SSH
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- Check what process is using port 22
- Stop conflicting sshd processes
- Disable socket activation conflict (systemd)
- Review sshd_config ListenAddress configuration
sudo lsof -i :22# orsudo netstat -tulpn | grep :22# or (modern systems)sudo ss -tulpn | grep :22error: 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
- 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)
- Systemd socket activation conflicting with sshd service (socket and service both trying to bind)
- IPv6 binding issue where IPv6 socket is listening on both IPv4 and IPv6 without SO_V6ONLY flag
- SSH configuration specifies both ListenAddress directives and socket activation is also configured
- 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."
Use one of these commands to identify what's bound to port 22:
sudo lsof -i :22
# or
sudo netstat -tulpn | grep :22
# or (modern systems)
sudo ss -tulpn | grep :22Output will show the process name and PID. If you see sshd, note the PID for the next step.
If multiple sshd instances are running, stop them with:
sudo systemctl stop sshd
# or on some systems
sudo systemctl stop ssh
# Force kill any remaining processes (be careful!)
sudo killall sshdWait 10-15 seconds for TIME_WAIT state to clear, then proceed to restart.
On systems using systemd socket activation, the ssh.socket might be competing with sshd for the port. Check if this is active:
sudo systemctl status ssh.socket
sudo systemctl status sshd.socketIf active, disable it:
sudo systemctl stop ssh.socket
sudo systemctl disable ssh.socket
sudo systemctl stop sshd.socket
sudo systemctl disable sshd.socketThen restart just the service:
sudo systemctl restart sshd
# or
sudo systemctl restart sshCheck your SSH configuration for duplicate or conflicting listen addresses:
sudo grep -n ListenAddress /etc/ssh/sshd_configCommon configurations:
- Listen on both IPv4 and IPv6 (default):
ListenAddress 0.0.0.0
ListenAddress ::- Listen on IPv4 only:
ListenAddress 0.0.0.0
# Comment out: # ListenAddress ::- Listen on IPv6 only:
ListenAddress ::
# Comment out: # ListenAddress 0.0.0.0If you have conflicting entries or custom ports, ensure they're consistent. After editing, validate with:
sudo sshd -tAfter making changes, restart the SSH service:
sudo systemctl restart sshdCheck that it started successfully:
sudo systemctl status sshdVerify the port is listening:
sudo ss -tulpn | grep :22You should see sshd listening on both 0.0.0.0:22 (IPv4) and [::]:22 (IPv6), or whichever you configured.
Test SSH connectivity from another machine:
ssh -v user@hostname.example.comThe -v flag shows verbose output if there are any issues. If connection succeeds, the error is resolved.
For local testing without a second machine:
ssh localhostAdvanced 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:
sudo sshd -D -dThis 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
- ๐SSH Official Documentation
- ๐OpenSSH sshd_config Manual - ListenAddress Configuration(Official Docs)
- ๐