To connect over SSH to an IPv6 address, ssh takes the address as is (ssh admin@2001:db8::10) and ssh -6 forces IPv6. scp and sftp, however, need brackets (scp file 'admin@[2001:db8::10]:/tmp/') because they use the colon to separate the path. On the server, ListenAddress :: and AddressFamily decide whether sshd listens on IPv6.

How to connect over SSH to an IPv6 address with ssh -6

ssh -6 forces the OpenSSH client to use IPv6 addresses only, and ssh -4 does the opposite. That helps when a hostname has both A and AAAA records and you need to know which path actually works. With a literal address you don't need it: the client already knows it is IPv6. The usual cases:

# Force IPv6 even if the name has A and AAAA records
ssh -6 [email protected]

# Literal address: no brackets
ssh admin@2001:db8::10
ssh -p 2222 admin@2001:db8::10

# Link-local: the interface is required
ssh admin@fe80::1%eth0

# Copying files: brackets required, and quoted
scp backup.tar.gz 'admin@[2001:db8::10]:/tmp/'
scp -P 2222 'admin@[2001:db8::10]:/var/log/syslog' .
sftp 'admin@[2001:db8::10]'

# Local forward to the server's IPv6 loopback
ssh -L '8080:[::1]:80' admin@2001:db8::10

# See in the debug log which address is actually used
ssh -6 -v [email protected]

Link-local addresses (fe80::/10) only exist on a single link, so they need a zone index after %: the interface name, such as eth0 on Linux or en0 on macOS. Without it, the system cannot tell which interface to send from.

For a server you reach every day, pin the address family in ~/.ssh/config. In HostName the address goes without brackets, because the port has its own directive:

Host nas6
    HostName 2001:db8::20
    User admin
    Port 2222
    AddressFamily inet6

From then on, ssh nas6, scp file nas6:/tmp/ or sftp nas6 is enough. The alias saves you from typing the address and, with it, the brackets.

Brackets in SSH over IPv6: syntax table compared with IPv4

There is one rule: brackets are required whenever the format uses a colon to separate the address from something else, either a path or a port. Since OpenSSH 9.0 (April 2022) scp uses the SFTP protocol by default, but the command-line syntax did not change and the brackets are still needed.

ContextWith IPv4With IPv6Brackets?
Interactive sshssh [email protected]ssh admin@2001:db8::10No
ssh with a portssh -p 2222 [email protected]ssh -p 2222 admin@2001:db8::10No, the port goes in -p
scpscp f [email protected]:/tmp/scp f 'admin@[2001:db8::10]:/tmp/'Yes
sftpsftp [email protected]sftp 'admin@[2001:db8::10]'Yes
ssh -L destination-L 8080:127.0.0.1:80-L '8080:[::1]:80'Yes
HostName in ~/.ssh/configHostName 203.0.113.10HostName 2001:db8::10No
known_hosts on a port other than 22[203.0.113.10]:2222[2001:db8::10]:2222Yes, for both families
ListenAddress with a portListenAddress 0.0.0.0:2222ListenAddress [::]:2222Yes

AddressFamily and ListenAddress :: in sshd_config to listen on IPv6

OpenSSH listens on TCP port 22 by default, and the AddressFamily directive in sshd_config (any, inet or inet6) decides which families it listens on. With inet, the server ignores IPv6 even if the machine has a public IPv6 address. To listen on both explicitly:

# /etc/ssh/sshd_config
AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::

# Check the syntax before restarting
sudo sshd -t

# Restart (the unit is called ssh or sshd depending on the distribution)
sudo systemctl restart ssh

# Confirm there is a socket on [::]:22
ss -tln | grep ':22'

ListenAddress :: binds every IPv6 address on the host; you can replace it with a specific one, such as ListenAddress 2001:db8::10. For another port, use brackets: ListenAddress [::]:2222. If your distribution starts sshd through systemd socket activation, addresses and ports come from the ssh.socket unit, not from ListenAddress. The full reference is in the official sshd_config manual page. Keep your current session open while you test from a second one, so you can still fix a mistake.

5 common errors when connecting over SSH to an IPv6 address

  1. scp without brackets. scp f admin@2001:db8::10:/tmp/ fails because scp splits at the first colon and treats the rest as the path. Wrap the address: 'admin@[2001:db8::10]:/tmp/'.
  2. Unquoted brackets in zsh. zsh reads […] as a filename pattern and, when nothing matches, aborts with "no matches found" before scp even runs. Single quotes around the destination avoid this in any shell.
  3. Link-local without an interface. fe80::1 without %eth0 gives no outgoing interface, so the connection never happens. In scp the zone goes inside the brackets: 'admin@[fe80::1%eth0]:/tmp/'.
  4. sshd listening on IPv4 only. AddressFamily inet or a single ListenAddress 0.0.0.0 leaves port 22 closed over IPv6, and the client gets "Connection refused". ss -tln confirms it in seconds.
  5. Forgotten IPv6 firewall. iptables rules do not apply to IPv6 traffic, which is filtered by ip6tables. With nftables, check that the port 22 rule lives in an inet or ip6 table.

SSH over IPv6 from iOS and Android with termi1

termi1 is an SSH, Mosh and SFTP terminal for iOS and Android, built by Sinergia in Barcelona, and the full terminal works without an account. The bracket rules above belong to OpenSSH and apply on a phone just the same; what changes is how you type and check those commands.

  • Its own keyboard. Esc, Ctrl, Tab and arrow keys are always visible, and the fn layer adds Home and End to jump along a long line and fix an address without retyping it.
  • AI that types without pressing Enter. Ask for "copy backup.tar.gz to /tmp on 2001:db8::10" and the command lands in the prompt so you can check the brackets. In Review mode it never presses Enter; on production connections, Production Guard holds back anything that deletes, stops or changes something.
  • Mosh and tmux. Mosh keeps the session alive when you move from wifi to mobile data, and tmux keeps whatever you left running. Mosh does no port forwarding: a -L '8080:[::1]:80' tunnel needs a plain SSH connection.
  • Built-in SFTP. Upload and download files without leaving the session or fighting scp syntax.
  • Keys stay on the device. SSH keys are generated on the phone and stored in the system's secure storage; the private key never leaves it.

If the server has no public IPv6 address and no open ports, a private mesh network without ports such as Prialo, or Tailscale, gives you another route. The app is free: get termi1 on the App Store or on Google Play.

Frequently asked questions

Why does scp need brackets for IPv6 when ssh does not?

scp needs brackets for IPv6 because it uses the colon to separate the host from the remote path, and an IPv6 address already contains several colons. ssh takes the port through -p and has no path, so it accepts the literal address. sftp follows the same rule as scp.

How do I make sshd listen on IPv6?

sshd listens on IPv6 when AddressFamily is set to any or inet6 and sshd_config contains ListenAddress :: or a specific IPv6 address. After editing the file, validate it with sudo sshd -t, restart the service and check with ss -tln that a socket on [::]:22 appears.

How do I remove an IPv6 address from known_hosts?

An IPv6 address is removed from known_hosts with ssh-keygen -R followed by the address, for example ssh-keygen -R 2001:db8::10. If the server runs on a port other than 22, the entry is stored with brackets and the port, so the command becomes ssh-keygen -R '[2001:db8::10]:2222'.

What can I do if my server has no public IPv6 address?

A server without a public IPv6 address or open ports is still reachable through a private mesh network such as Prialo or Tailscale. The client connects to the address that network assigns, and the bracket rules for scp and sftp still apply whenever that assigned address is IPv6.