Skip to main content

Installation and Setup

SCP is bundled with OpenSSH, which is pre-installed on virtually every Linux distribution. This page covers verification, SSH key setup, and SSH config shortcuts to streamline SCP usage.

Verify Installation​

SCP is part of the openssh-client package.

Command:

which scp

Output:

/usr/bin/scp

If scp is not found, install it:

# Debian/Ubuntu
sudo apt install openssh-client

# RHEL/CentOS/Fedora
sudo dnf install openssh-clients

SSH Key Setup​

Using SSH keys eliminates password prompts during SCP transfers, which is essential for scripting.

1. Generate a Key Pair​

Command:

ssh-keygen -t ed25519 -C "scp-transfer-key"

Output:

Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/user/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Your identification has been saved in /home/user/.ssh/id_ed25519
Your public key has been saved in /home/user/.ssh/id_ed25519.pub

2. Copy Public Key to Remote Server​

Command:

ssh-copy-id user@192.168.1.100

Output:

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s)
Number of key(s) added: 1

Now try logging into the machine, with: "ssh 'user@192.168.1.100'"

3. Verify Password-less Access​

Command:

ssh user@192.168.1.100 "echo 'SSH key works'"

Output:

SSH key works

SSH Config for Shortcuts​

Create or edit ~/.ssh/config to define host shortcuts:

~/.ssh/config
Host prod-server
HostName 192.168.1.100
User deploy
Port 22
IdentityFile ~/.ssh/id_ed25519

Host staging
HostName 10.0.0.50
User admin
Port 2222
IdentityFile ~/.ssh/id_ed25519

Now you can use the alias in SCP:

Before:

scp -P 2222 -i ~/.ssh/id_ed25519 ./app.tar.gz admin@10.0.0.50:/opt/releases/

After:

scp ./app.tar.gz staging:/opt/releases/

Common Setup Pitfalls​

IssueCauseFix
Permission denied (publickey)Key not on remote serverRun ssh-copy-id user@host
WARNING: UNPROTECTED PRIVATE KEY FILEKey file permissions too openchmod 600 ~/.ssh/id_ed25519
Connection refusedSSH not running on targetsudo systemctl start sshd
No route to hostFirewall blocking port 22Check ufw status or cloud security group

What's Next?​

Now that SSH is set up, move on to Basic Copy to start transferring files.