Skip to main content

Port and Identity

By default, SCP connects over SSH port 22. In production environments, servers often use non-standard ports and specific SSH keys for different services.

Custom SSH Port

Use the -P flag (uppercase) to specify a non-default SSH port.

Note the Uppercase -P

SCP uses uppercase -P for port. This differs from ssh which uses lowercase -p. This is a common source of confusion.

Example: Copy to Server on Port 2222

Command:

scp -P 2222 ./deploy.tar.gz admin@server:/opt/releases/

Output:

deploy.tar.gz                          100%  120MB  38.5MB/s   00:03

Example: Download from Non-Standard Port

Command:

scp -P 8022 admin@bastion:/var/log/auth.log ./

Output:

auth.log                               100%   25MB  30.0MB/s   00:00

Identity Files

Use the -i flag to specify which SSH private key to use.

Example: Use a Specific Key

Command:

scp -i ~/.ssh/deploy_key ./app.jar deploy@prod-server:/opt/app/

Output:

app.jar                                100%   85MB  42.0MB/s   00:02

Example: Combine Port and Identity

Command:

scp -P 2222 -i ~/.ssh/staging_key ./config.yml admin@staging:/etc/app/

Output:

config.yml                             100% 2048     1.5MB/s   00:00

SSH Config Integration

Instead of typing flags every time, define hosts in ~/.ssh/config:

~/.ssh/config
Host production
HostName 203.0.113.50
User deploy
Port 2222
IdentityFile ~/.ssh/deploy_key

Host staging
HostName 10.0.0.25
User admin
Port 8022
IdentityFile ~/.ssh/staging_key

Example: Using SSH Alias

Before (long form):

scp -P 2222 -i ~/.ssh/deploy_key ./release.tar.gz deploy@203.0.113.50:/opt/releases/

After (with SSH config):

scp ./release.tar.gz production:/opt/releases/

Output:

release.tar.gz                         100%  200MB  45.0MB/s   00:04

Custom SSH Config File

Use -F to point to a non-default SSH config:

Command:

scp -F /etc/ssh/project-config ./data.csv project-host:/imports/

Output:

data.csv                               100%   50MB  35.0MB/s   00:01

What's Next?

Learn about compression and cipher selection in Compression and Performance.