Table of Contents
Overview
Anyone who administers Linux machines likely knows secure shell. Without this tool, administering those servers remotely would be quite challenging. It would also become harder to move files back and forth, at least with a modicum of security. That’s where secure copy comes into play. With the SCP command, you can copy files to and from a remote Linux server through an encrypted SSH tunnel.
scp (secure copy) command lets you securely transfer files between your local machine and a remote server over SSH.When you authenticate using an SSH key instead of a password, you use the
-i option to specify your private key file.SSH keys
SSH keys are a secure, password‑less way to log into servers. They’re used with SSH (Secure Shell) to authenticate you without typing a password every time.
scp -i ~/.ssh/id_rsa.pub FILENAME USER@SERVER:/home/USER/FILENAME scp -i ~/.ssh/id_rsa.pub USER@SERVER:/home/USER/FILENAME /home/USER/FILENAME ssh -i YourFile-OpenSSH-Internal.pem ec2-user@3.142.90.222
How They Work (Quick & Simple)
SSH keys come in a pair:
1. Private Key
- Stays on your computer
- Never share it
- Usually stored in
~/.ssh/id_rsaorid_ed25519
2. Public Key
- Goes on the server
- Stored in the server’s
~/.ssh/authorized_keys
When you connect, the server checks if your private key matches the public key.
If yes → you’re in. No password needed.
Generate a key (example)
ssh-keygen -t ed25519 -C "your_email@example.com"
This creates:
~/.ssh/id_ed25519→ private key~/.ssh/id_ed25519.pub→ public key
Key File Permission Requirements
SSH private keys must have restricted permissions:
chmod 600 ~/.ssh/id_rsa
If permissions are too open, you’ll see the following error:
Bad permissions: key file is too open
Basic Syntax
scp -i /path/to/private_key source destination # Copy a local file to the remote destination scp -i ~/.ssh/id_rda ./file.txt ec2-user@123.34.56.78:/home/ec2-user/data/
Some common usages
# Copy a remote file to the local machine scp -i ~/.ssh/id_rsa user@remote-host:/home/user/file.txt ./ # Copy an entire directory recursively scp -i ~/.ssh/id_rsa -r ./myfolder user@remote-host:/home/user/ # Specify a custom SSH port scp -i ~/.ssh/id_rsa -P 2222 file.txt user@remote-host:/home/user/
Speed up transfers (optional)
# Use compression scp -i ~/.ssh/id_rsa -C file.txt user@remote-host:/home/user/ # Increase performance for large transfers scp -i ~/.ssh/id_rsa -o "Cipher aes128-ctr" file.txt user@remote-host:/path/
Tips & Alternatives
Use rsync for large or repeat transfers
rsync -avz -e "ssh -i ~/.ssh/id_rsa" ./folder user@remote-host:/path/
For Windows with PuTTY .ppk key
Convert the key using PuTTYgen → export to OpenSSH format.
References
[1] How To Use SCP (Secure Copy) With SSH Key Authentication, accessed on 26th Dec 2025
[2] Tutorial: Secure Copy (SCP) – Transfer Files Securely Over SSH, accessed on 26th Dec 2025
