The SSH (Secure Shell) protocol is a network protocol for remote command-line management of operating systems, widely considered the standard for remote access to *nix machines. It allows secure login to a server, remote command execution, file management (creating, deleting, copying, etc.), and more. Most cloud and hosting providers require SSH to access their services. In this article, we’ll look at how to copy files over SSH on both Windows and Linux systems.
SSH can securely transmit any data (audio, video, application protocol data) through an encrypted communication channel. Unlike outdated and insecure protocols like Telnet and rlogin, SSH ensures data confidentiality and authenticity — essential for internet communications.
Here’s how a secure connection between a client and server is established:
TCP Connection Setup: By default, the server listens on port 22. Both sides share a list of supported algorithms (compression, encryption, key exchange) and agree on which to use.
Authentication: To prevent impersonation, both parties verify each other's identities using asymmetric encryption (public/private key pairs). First, the server is authenticated. On the first connection, the client sees a warning with server details. Trusted server keys are stored in /home/<username>/.ssh/known_hosts
.
Key Generation: Once the server is verified, both sides generate a symmetric key to encrypt all data exchanged.
User Authentication: This is done using either a password or a client-sent public key stored in /home/<username>/.ssh/authorized_keys
on the server.
The most popular implementation on Linux is OpenSSH, which comes pre-installed on most distributions (Ubuntu, Debian, RHEL-based, etc.). Clients like PuTTY or MobaXterm are used on Windows. Since Windows 10 and Server 2019, OpenSSH tools are also available natively.
You can learn more about working with SSH in our tutorial.
Two main utilities for copying files over SSH in Linux are scp
and sftp
. Both come with OpenSSH.
SSH supports two protocol versions: 1 and 2. OpenSSH supports both, but version 1 is rarely used.
To enable Tab-based autocompletion when using scp
, set up public key authentication:
Generate a key pair:
ssh-keygen
You’ll see output like:
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
By default, your keys (id_rsa
for private and id_rsa.pub
for public) are saved to ~/.ssh/
.
Now copy the public key to the remote machine:
ssh-copy-id [username]@[ip-address]
After entering the user's password, you’ll see a message confirming the key was added.
For small data transfers (e.g., service configs), scp
is best.
Copy from local to remote:
scp test.txt user@192.168.1.29:/home/user/
Copy multiple files:
scp test1.txt test2.txt user@192.168.1.29:/home/user/
Copy from remote to local:
scp user@192.168.1.29:/home/user/test.txt ~/
Copy directories:
scp -r testdir user@192.168.1.29:/home/user/
Remote-to-remote copy:
scp gendo@192.168.1.25:/home/gendo/test.txt user@192.168.1.29:/home/user/
SFTP is another utility included in OpenSSH. As of OpenSSH 9.0, scp now uses SFTP by default instead of the old SCP/RCP protocol.
Unlike classic FTP, sftp transmits encrypted data over a secure tunnel. It does not require a separate FTP server.
Example usage:
sftp misato@192.168.1.29
sftp> ls
sftp> lcd testdir/
sftp> get test.txt
sftp> bye
Graphical file managers like Midnight Commander and Nautilus use sftp
. In Nautilus, the remote server appears like a local folder, e.g., user@ip
.
Use the pscp command-line tool from PuTTY to copy files on Windows.
Copy to server:
pscp C:\server\test.txt misato@192.168.1.29:/home/misato/
Copy from server:
pscp misato@192.168.1.29:/home/misato/test.txt C:\file.txt
List files on remote server:
pscp -ls user@192.168.1.29:/home/misato
Use quotes for paths with spaces:
pscp "C:\dir\bad file name.txt" misato@192.168.1.29:/home/misato/
To get help, run:
pscp
We’ve covered how to copy files to and from a server using the secure SSH protocol. If you work with cloud servers, understanding SSH is essential — it’s the standard method for remote access to *nix machines and a vital part of everyday DevOps and system administration.