183

Does SFTP use port 21 or port 22?

Peter Mortensen
  • 2,319
  • 5
  • 23
  • 24
Daniel
  • 3,741
  • 7
  • 32
  • 33

6 Answers6

236

While TCP port 22 is the general right answer, this is dependent on the fact that SSH is configured to use the standard port and not an alternative port.

As SFTP runs as a subsystem of SSH it runs on whatever port the SSH daemon is listening on and that is administrator configurable.

Jeremy Bouse
  • 11,241
  • 2
  • 27
  • 40
  • 10
    sftp command line syntax for alternate ports `sftp -oPort=### user@server.tld` – here Nov 08 '13 at 04:06
  • for schemes see https://stackoverflow.com/a/30093291/712334 – vhs Aug 31 '18 at 09:24
  • It's not really clear what is administrator configurable. They can both be running on a different port? They can be running on different ports? Can SFTP run w/o an SSH daemon? – x-yuri May 16 '22 at 05:08
117

SFTP usually uses port 22 but can be configured to run on nearly any port.

Port 22 is generally used for connection via SSH. SFTP is just one of protocols which can be run over SSH (others include virtual terminal). In fact, the SFTP is independent and can be run even without using SSH.

SFTP is sometimes called "Secure FTP" which leads to a common confusion with FTPS (which is called "Secure FTP" too).

Generally:

SFTP - SSH File Transfer Protocol - usually runs over TCP port 22

FTP - plain, old file transfer protocol - usually runns over TCP port 21 (+ opens separate ports for data transfer)

FTP/SSL - FTP over TLS/SSL channel.

FTPS - same as FTP/SSL

Secure FTP - either SFTP or FTPS

More info:

Vesper
  • 754
  • 1
  • 9
  • 29
Martin Vobr
  • 1,313
  • 1
  • 8
  • 11
  • 2
    I agree that sftp listens on 22, but why does my /etc/services say it's 115 (on Ubuntu)? – Paul A Jungwirth Jul 29 '14 at 18:32
  • 4
    @Paul-A-Jungwirth: It's just the same acronym for unrelated protocol. SFTP on port 115 stands for Simple File Transfer Protocol - http://en.wikipedia.org/wiki/Simple_File_Transfer_Protocol. The SFTP on port 22 is SSH File Transfer Protocol. http://en.wikipedia.org/wiki/SSH_File_Transfer_Protocol – Martin Vobr Jul 29 '14 at 21:44
13

It uses whatever port SSH is setup to use.

Michael Pobega
  • 934
  • 5
  • 12
9

Its uses Port 22.

0

@Paul A. Jungwirth Good question about 115. I think it states decimal 115 as that's an older, unsecure version of SFTP protocol, before SSH had been invented - from 1984 Simple File Transfer Protocol - https://www.rfc-editor.org/rfc/rfc913#page-1

SSH only suggests TCP:22 - but it's not required by any NAT algorithms like FTP does so it can be any port that admin sets up. Port 22 is only the default used in most installations.

-9

SFTP will also use data ports at higher ranges. SSH will remain the control port. It uses more than 22 in most instances...

  • 5
    This answer is incorrect. SFTP transfers all data over the SSH connection. No additional port is used. – kasperd Jul 11 '14 at 06:28
  • You are confusing SFTP and FTPS. SFTP = FTP over SSH, FTPS = FTP using SSL certificates. SFTP may use Port 20 to initiate SFTP transfer but then remain on 22, FTPS often use higher ranges of ports.. e.g.10000-11000 – Andras Jul 04 '20 at 12:00