월. 8월 4th, 2025

If you work with Linux servers or remote systems, SCP (Secure Copy Protocol) is an essential tool for transferring files securely. Built on SSH (Secure Shell), it encrypts your data during transit. Here’s a step-by-step guide to master SCP!


⚙️ Prerequisites

Before starting, ensure:

  1. SSH access to the remote server.
  2. Username and IP address/hostname of the remote machine.
  3. Firewall permissions for SSH (default port: 22).

📋 Basic SCP Syntax

scp [options] [source] [destination]
  • [source] and [destination] can be:
    • Local: /path/to/local/file
    • Remote: username@remote_host:/path/to/remote/directory

🔧 Common Use Cases

1. Local → Remote File Transfer

scp myfile.txt john@203.0.113.25:/home/john/documents/
  • Copies myfile.txt to the remote server’s documents directory.

2. Remote → Local File Transfer

scp john@203.0.113.25:/var/log/app.log /home/yourname/downloads/
  • Downloads app.log from the remote server to your local downloads folder.

3. Copy Between Two Remote Servers

scp user1@server1.com:/data/file.zip user2@server2.com:/backups/
  • Transfers file.zip directly from server1 to server2 (uses your local machine as a bridge).

🛠️ Useful Options

Option Description
-P 2222 Use custom SSH port (e.g., 2222 instead of 22).
-r Copy directories recursively (e.g., scp -r my_folder/ user@host:/target/).
-i ~/.ssh/key.pem Use a specific SSH private key.
-C Enable compression (faster for large files).
-v Verbose mode (debug connection issues).

🔒 Security Notes

  • SCP uses SSH encryption, making it safe for sensitive data.
  • Avoid storing passwords in commands! Use SSH keys for authentication:
    # Generate keys (if needed)  
    ssh-keygen -t ed25519  
    ssh-copy-id user@remote_host  

❗ Troubleshooting Tips

  • “Permission denied” error?
    • Verify remote directory permissions: chmod 700 ~/target_folder.
  • Connection timeout?
    • Check SSH port/firewall: ssh -p 2222 user@host (replace 2222 with your port).
  • “No such file” error?
    • Use absolute paths (e.g., /home/john/file.txt instead of ~/file.txt).

🚀 Alternatives to SCP

For frequent transfers, consider:

  • rsync: Better for syncing large directories (supports incremental transfers).
  • SFTP clients: GUI tools like FileZilla or WinSCP.

💡 Final Thoughts

SCP is fast, secure, and pre-installed on most Linux/macOS systems. For Windows, use WinSCP or enable SSH via PowerShell. Start with simple file transfers, then explore options like -r for directories!

> ✨ Pro Tip: Combine SCP with SSH config shortcuts for faster logins. Add hosts to ~/.ssh/config:
> > Host myserver > HostName 203.0.113.25 > User john > Port 2222 >
> Then run: scp file.txt myserver:/backups/

Happy transferring! 🐧🔐

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다