Installing the scp Command on CentOS

When moving files between two virtual machines in a test environment, the first instinct is usually the scp command — which immediately bounces back with:

-bash: scp: command not found

Naturally, you try yum install scp, only to be told:

No package scp available.

Why scp can't be found

scp isn't a standalone package; it ships inside openssh-clients. On a full CentOS install that package arrives with the OpenSSH client, but a minimal install drops it to keep the image small — so scp, sftp, and ssh-keygen are all missing. That's why yum install scp finds no matching package.

Reference: OpenSSH manual https://www.openssh.com/manual.html; on CentOS the command is provided by openssh-clients — confirm with yum whatprovides '*/scp'.

The fix

Install openssh-clients:

yum install openssh-clients -y

Then try again:

scp 1.so [email protected]:/root/

After entering the password, the same error shows up:

bash: scp: command not found

That's because scp transfers need the component on both ends: your machine is the client, the destination is the server. Although sshd usually pulls in openssh-clients as a dependency, some minimal distributions don't enforce it. Install openssh-clients on the target host too:

yum install openssh-clients -y

Try once more and it works. Verify with which scp.

Common scp usage

scp's syntax mirrors cp, with a host prefix added:

# Local -> remote
scp ./backup.tar.gz [email protected]:/root/backup/

# Remote -> local
scp [email protected]:/root/logs/app.log ./logs/

# Custom port (when ssh isn't on 22)
scp -P 2222 ./file [email protected]:/root/

# Recursive directory copy
scp -r ./site/ [email protected]:/var/www/

# Preserve timestamps and permissions
scp -p ./config.conf [email protected]:/etc/

Handy flags: -P sets the port (uppercase), -r recurses into directories, -p preserves file attributes, -C enables compression, and -i selects a key file. For large directories rsync -avz beats scp (resume support and delta sync), but for one or two files scp is the most direct option.

One more trick: scp pairs with pipes for streaming — tar czf - ./data | ssh [email protected] 'tar xzf - -C /opt/data' packs and transfers in one step, skipping the intermediate temp file. When the network is average, compressing before transfer is usually noticeably faster than a raw copy.

Troubleshooting common issues

1. "Permission denied (publickey,password)"

The password is right but this keeps appearing — it's usually not scp's fault. Either PasswordAuthentication is set to no in the target's /etc/ssh/sshd_config, or SELinux/firewall (e.g., firewalld) is blocking port 22. First test whether ssh [email protected] works at all; if you can't log in with ssh, scp won't work either.

2. "Host key verification failed"

When connecting to a new host for the first time, or after a host was rebuilt and its key changed, ssh refuses to connect. Once you've confirmed the host is trustworthy, remove the stale host key and retry:

ssh-keygen -R 192.168.0.182

3. Slow transfers

First check whether the network itself is slow, then consider scp -C to enable compression (useful for text, logs, and source code; counterproductive for already-compressed tarballs). For large directories, rsync -avz --progress is better — it resumes after interruption and skips files already transferred.

scp vs. other transfer methods

Method Best for Resumable Encrypted Notes
scp One-off files No SSH Most direct, nothing to install
rsync Large dirs, incremental sync Yes Via SSH Most efficient; recommended daily driver
sftp Interactive remote browsing Manual SSH FTP-like but over SSH
wget/curl Pulling from HTTP/HTTPS Partial Depends on protocol Great for public resources

For day-to-day ops, scp usually plays the role of "quickly push a config file": shipping an edited nginx.conf to production, or pulling production logs back for troubleshooting. In those cases, the three flags you'll actually need are -P for port (uppercase), -r for recursive, and -p to preserve attributes.

Here's a realistic scenario: you need to push a local release-2026.08.tar.gz (about 3.2GB) to a production server. A raw scp will saturate the bandwidth and slow down the site for everyone. The safer play is to package with tar if the content compresses, then push with rsync -avz --bwlimit=20480 to cap throughput at 20MB/s, adding --partial so an interrupted run can resume. For "big file, don't block the business" cases like this, scp isn't the first choice.

Passwordless transfers with SSH keys

If typing a password every time gets old, set up SSH key login and scp stops prompting entirely:

# Generate a key pair on your machine (press Enter to accept defaults)
ssh-keygen -t ed25519 -C "[email protected]"

# Push the public key to the target host
ssh-copy-id [email protected]

After that, scp ./file [email protected]:/root/ just works. Combine it with -i ~/.ssh/id_ed25519 to select a key, or use ssh-agent to manage multiple keys, so scp inside scripts never stalls on a password prompt. Keys are also more secure than passwords — ed25519 is shorter and faster than legacy RSA 2048 and is the current default recommendation.

Summary

When scp is missing, don't jump straight to network or permission debugging — in most cases it's just the minimal install that skipped openssh-clients, and a quick install fixes it. Keep the points below in mind and you won't get stuck again:

  1. The scp command is provided by the openssh-clients package; yum install scp is not a valid package name.
  2. On command not found, first check whether openssh-clients is installed locally with rpm -q openssh-clients.
  3. When transferring to a target host, the target host also needs openssh-clients (usually provided by the sshd dependency, but it may be missing on a minimal install).
  4. After installing, verify with which scp.

scp is a common command for securely transferring files between Linux servers. For detailed scp parameters and usage examples, refer to Linux scp file transfer. For more server operations content, see the cloud servers category, such as server operations tips.

Original post: https://www.cnblogs.com/cqzhuomi/articles/17284333.html (cnblogs.com CQZHUOMI, repost)