SFTP and SSH are often mentioned together, but they are not the same thing: SSH is a secure network protocol for remote login and command execution, while SFTP is a secure file transfer protocol that runs over an SSH connection. In short, SSH is the secure tunnel, and SFTP is a file-transfer service that uses that tunnel. This article explains how each works, how they relate, and how to choose the right one for your needs.
Background: Where SSH and SFTP Came From
SSH (Secure Shell) was created in 1995 by Tatu Ylönen as a replacement for insecure remote login protocols like Telnet, rlogin, and rsh. Those older protocols sent passwords and data in plain text, so anyone on the network could intercept them. SSH encrypts the entire session, protecting both the login credentials and the commands or data exchanged.
SFTP (SSH File Transfer Protocol) is a separate protocol that was designed later, not as part of the original SSH specification but as an extension of it. The first version appeared in 1997 as part of the SSH 2.0 draft. It is sometimes called “Secure File Transfer Protocol” but it is not related to FTPS, which is FTP over TLS/SSL. SFTP uses the same port and the same SSH connection as remote shell access, but it provides file-management operations instead of a command line.
How SSH Works
SSH establishes an encrypted connection between a client and a server. The typical flow is:
- The client connects to the server on TCP port 22.
- The server presents its host key; the client verifies it (often via a fingerprint).
- The two sides negotiate encryption algorithms and exchange session keys.
- The client authenticates, usually with a password or a public-key pair.
- Once authenticated, the client can run a shell, execute commands, or forward ports.
SSH is used for remote administration, tunneling other protocols (like X11 or SOCKS), and securely forwarding ports. It is the foundation that makes SFTP possible, but SSH itself does not transfer files—it provides the secure channel.
How SFTP Works
SFTP is a subsystem of SSH, not a separate daemon. When you run an SFTP client, it opens an SSH connection and then requests the SFTP subsystem on the server. After that, the client and server exchange SFTP messages to list directories, upload, download, rename, delete, and change permissions.
Because SFTP rides on SSH, it inherits all of SSH’s security features: encryption, host key verification, and authentication (password, public key, or even two-factor). It uses the same port 22, so no additional firewall rules are needed beyond those for SSH. SFTP also supports resuming interrupted transfers, something plain FTP does not do well.
Key Differences Between SSH and SFTP
The easiest way to think about it: SSH is the vehicle, SFTP is the cargo service. Here are the concrete differences:
- Function: SSH is for remote shell access and command execution; SFTP is for file transfer and management.
- Port: Both use TCP port 22 by default, but SFTP is a subsystem of SSH, not a separate protocol.
- Commands: SSH uses a shell (like bash); SFTP has its own set of commands (get, put, ls, cd, etc.).
- Data: SSH can tunnel any kind of traffic; SFTP only handles file operations.
- Authentication: Both use the same SSH authentication methods, but SFTP cannot work without SSH.
Which One Should You Use?
It depends on your task:
- If you need to log into a server and run commands, use SSH (for example,
ssh user@host). - If you need to upload, download, or manage files securely, use SFTP (for example,
sftp user@host). - If you need to automate file transfers, SFTP scripts or tools like
scp(which also uses SSH) are common choices. - If you need to forward a port or tunnel a protocol, SSH is the tool.
Most modern SSH clients (like OpenSSH) include both an SSH shell and an SFTP client. Some graphical tools (like WinSCP or FileZilla) use SFTP under the hood but present a familiar file-manager interface.
Common Problems and Misconceptions
One widespread misconception is that SFTP and FTPS are the same. They are not: FTPS is FTP over TLS, a completely different protocol that uses separate control and data connections and often requires multiple ports. SFTP is simpler because it uses a single SSH connection.
Another issue is host key verification. When you connect to a new server, SSH asks you to confirm the host key fingerprint. If you skip this check (or blindly accept), you are vulnerable to man-in-the-middle attacks. Always verify the fingerprint with the server administrator.
Performance can also be a problem. SFTP can be slower than plain FTP because of encryption overhead, but that is the price for security. If speed is critical, consider using SSH with compression or a faster cipher, but never disable encryption.
Safety and Best Practices
To use SSH and SFTP safely:
- Use public-key authentication instead of passwords whenever possible.
- Disable password login on servers if you rely on keys.
- Keep your private keys secure and passphrase-protected.
- Use a firewall that only allows SSH from trusted IPs if possible.
- Keep SSH software updated to avoid known vulnerabilities.
- Never share your private key or use weak passphrases.
Frequently Asked Questions
Is SFTP the same as FTPS?
No. SFTP is a file transfer protocol that runs over SSH (port 22). FTPS is FTP over TLS/SSL and uses multiple ports. They are incompatible with each other.
Can I use SSH to transfer files?
Yes, but not directly. SSH provides the secure channel; you would use an SSH-based tool like SCP (Secure Copy) or SFTP to actually transfer files.
Do I need to install SFTP separately?
No. Most SSH servers, such as OpenSSH, include an SFTP subsystem by default. You just need an SFTP client (like the sftp command or a GUI tool).
Why does SFTP use port 22?
Because SFTP runs as a subsystem of SSH, it uses the same TCP port 22. You only need to open that one port in your firewall for both SSH and SFTP.
Is SFTP secure enough for sensitive data?
Yes, SFTP is considered secure because it encrypts both the authentication and the data in transit. However, the security also depends on the strength of your SSH keys and the server configuration.
Can I resume an interrupted SFTP transfer?
Yes, most SFTP clients support resuming by using the reget command (or a similar option in GUI tools). This is a big advantage over plain FTP.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Omega ORU52X Specs: What They Mean for You42.00 cu ft
- AI Agent State Safety During Context Compaction
- Games Like Assassin’s Creed: 12 Open-World Picks
- KCD2 Blacksmith’s Son Quest Guide
- Delete Stations Pandora? How to Remove Them
- How to Play Brawl Stars Without an Emulator