Installing the scp Command on CentOS (openssh-clients)
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:
- The
scpcommand is provided by theopenssh-clientspackage;yum install scpis not a valid package name. - On
command not found, first check whetheropenssh-clientsis installed locally withrpm -q openssh-clients. - 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).
- 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)
Integration & Code Examples
Example 1: Install openssh-clients and transfer files both ways
# scp ships in openssh-clients, which minimal installs leave out
yum install -y openssh-clients
yum whatprovides '*/scp'
which scp && scp -V
# Local -> remote (-P sets the port; note the capital P)
scp -P 2222 ./backup.tar.gz [email protected]:/data/backup/
# Remote -> local (-p preserves timestamps and permissions)
scp -p [email protected]:/var/log/nginx/access.log ./logs/
# Copy a whole directory recursively
scp -r ./site/ [email protected]:/data/www/
# For passwordless transfers, push the key first and rerun the same scp
ssh-keygen -t ed25519 -N '' -f ~/.ssh/id_ed25519
ssh-copy-id -p 2222 [email protected]
command not found is a packaging problem, not a password problem: confirm the package with yum whatprovides, then check that sshd runs on both ends.
Example 2: Use rsync instead of scp for incremental copies
yum install -y rsync
# -a archive mode, -z compression, -P progress plus resumable transfers
rsync -avzP -e 'ssh -p 2222' ./site/ [email protected]:/data/www/
# Rehearse deletions with --dry-run before letting --delete run for real
rsync -avzn --delete ./site/ [email protected]:/data/www/
# Exclude VCS and dependency trees you never want on the server
rsync -avz --exclude='.git/' --exclude='node_modules/' \
./site/ [email protected]:/data/www/
--dry-run lists what would be deleted or overwritten without touching anything, which keeps --delete from wiping a document root.
Which Component Lives on Which Side
scp is not a standalone package: it ships inside openssh-clients, which is why yum install scp answers "No package scp available."
| Role | Component needed | Verify with | Symptom when missing |
|---|---|---|---|
| Sending side (client) | openssh-clients provides scp, sftp, ssh-keygen |
rpm -q openssh-clients, which scp |
bash: scp: command not found |
| Receiving side (server) | openssh-clients plus a running sshd |
systemctl status sshd, ssh user@host |
command not found persists after installing locally |
| Port and authentication | PasswordAuthentication in sshd_config, port open in firewalld |
ssh -p 2222 user@host succeeds |
Permission denied (publickey,password) |
| Host key | ~/.ssh/known_hosts |
ssh-keygen -R 192.168.0.182 |
Host key verification failed |
The second row is the one that surprises people: a minimal install on the receiving host can lack the client package even though sshd depends on parts of it, so the same yum install openssh-clients -y has to run on both ends.
Test with ssh before blaming scp. If plain ssh cannot log in, no scp flag will help, and the actual fault sits in authentication, the port, or the firewall.
Combining Transfer Flags: Port, Recursion, Attributes, Compression
-P takes the port and must be uppercase, while -r recurses into a directory and -p preserves timestamps and permissions. Confusing -P with -p is the most common cause of a transfer that "connects to the wrong place" or "loses the owner".
-C compresses in transit and only pays off on compressible payloads: text, logs and source code. On an already compressed archive such as .tar.gz it adds CPU time and can even slow the transfer down.
For a streamed copy, tar czf - ./data | ssh [email protected] 'tar xzf - -C /opt/data' packs and transfers in one step with no temporary file in between. -i pins a specific private key when several exist in ~/.ssh.
Limitations
- This article reflects public information as of 2023-04-03; terms, prices and quotas follow the provider's current published terms.
- Third-party capability and limit statements follow their official documentation; no further commitment is implied here.
- Licensing, filing and data-residency decisions must be verified against the regulations of your operating region.
FAQ
Why does yum install scp fail with no package?
You need openssh-clients instead: scp ships inside that package, and minimal installs on CentOS 7 and Rocky 9 omit it. Run yum install openssh-clients -y, confirm the provider with yum whatprovides '*/scp', then verify with rpm -q openssh-clients and which scp. A missing name means a wrong package name, not an empty repository.
What prerequisites must both hosts meet before scp works?
You need openssh-clients installed and sshd running on both hosts, plus working ssh access from local to target. Permission denied usually means password authentication is disabled on the target or the firewall blocks the port, so fix login first; when the port is not 22, both commands must carry the port flag.
How should you manage SSH keys for scp?
You need an ed25519 key pair with the public half on the target. Generate it with ssh-keygen -t ed25519, push it with ssh-copy-id, and scp stops prompting. With several hosts, point -i at the right private key or let ssh-agent hold it, so scripts never block on a prompt. Keys also suit automation better than passwords.
For large directories, should you use rsync instead?
Match the tool to size. A multi-GB release goes through rsync -avz --partial with --bwlimit=20480 to cap at 20MB/s so business traffic is not squeezed, while one or two config files need only scp -P, -r, -p. The real difference shows after a drop: rsync resumes, scp restarts, so anything over 1 GB should use rsync.
Related Providers
- Alibaba Cloud ECS: when the instance runs CentOS or Alibaba Cloud Linux and openssh-clients must come from its repos.
- Tencent Cloud: when the ssh client version bundled in a CVM image has to be verified before installing anything.
- Hetzner: when a self-built CentOS host needs root and key policy settled before scp transfers.
Community & Resources
Official docs and communities
- OpenSSH manuals — index of client and server documentation
- scp(1) manual (OpenBSD) — the original implementation and its parameter semantics
- Stack Overflow: scp — frequent questions on ports, permissions and failed transfers
- Stack Overflow: ssh — keys, authentication and host fingerprint issues
Learning resources and tools
- scp(1) manual (Linux) — behaviour differences on Linux distributions
- rsync(1) manual — reference for
--delete,--excludeand-e - openssh-portable repository — source, release notes and known issues
Original source: cnblogs.com (CQZHUOMI) ↗