Connect to a non-default SFTP port

SFTP, the abbreviation for SSH (or Secure) File Transfer Protocol is using by default port 22. Many servers nowadays are using different port numbers, like 2222. We will show in this article how to connect to an explicit port number, using the sftp utility.

The sftp command information:

root@web [~]# sftp
usage: sftp [-1246aCfpqrv] [-B buffer_size] [-b batchfile] [-c cipher]
          [-D sftp_server_path] [-F ssh_config] [-i identity_file] [-l limit]
          [-o ssh_option] [-P port] [-R num_requests] [-S program]
          [-s subsystem | sftp_server] host
       sftp [user@]host[:file ...]
       sftp [user@]host[:dir[/]]
       sftp -b batchfile [user@]host

To connect with sftp to a specific port as root, use:

# sftp -P port_number hostname
root@web [~]# sftp -P 2222
The authenticity of host '[]:2222 ([]:2200)' can'                                                                                        t be established.
ECDSA key fingerprint is SHA256:MqoUe1cJlbAqFidXZbV4cSMWfi1meCQ6ZtMiIzZ7yQE.
ECDSA key fingerprint is MD5:06:95:95:63:2f:ea:7a:4c:e7:36:62:73:f6:83:d2:04.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added '[]:2222' (ECDSA) to the list of known hosts.'s password:
Connected to
sftp> cd /
sftp> bye
root@web [~]#

To connect with a username, use:

# sftp -P port_number user@hostname

Leave a Reply