scp Command

What is Linux scp Command?
scp (Secure Copy Protocol) is a command-line utility for securely transferring files and directories between hosts over an SSH connection. It combines the functionality of the traditional cp command with SSH encryption, providing a secure way to copy files across networks.
scp uses SSH for data transfer and authentication, ensuring that your files are encrypted during transmission. It’s part of the OpenSSH suite and is available on most Unix-like systems including Linux, macOS, and Windows Subsystem for Linux.
From the man page:
scp copies files between hosts on a network. It uses ssh for data transfer, and uses the same authentication and provides the same security as ssh. scp will ask for passwords or passphrases if they are needed for authentication.
Key Features
- Secure transfer: Uses SSH encryption for secure file transfer
- Authentication: Supports SSH key-based and password authentication
- Recursive copying: Can copy entire directory structures
- Preserve attributes: Maintains file permissions and timestamps
- Cross-platform: Works between different Unix-like systems
- Simple syntax: Easy to use command-line interface
scp Syntax
scp [options] source destinationThe basic syntax follows the pattern:
- Local to Remote:
scp file.txt user@remote:/path/ - Remote to Local:
scp user@remote:/path/file.txt . - Remote to Remote:
scp user1@host1:/file user2@host2:/path/
Basic scp Examples
Copy File from Local to Remote
Transfer a single file to a remote server:
scp file.txt user@remote-server:/home/user/Copy File from Remote to Local
Download a file from a remote server:
scp user@remote-server:/home/user/file.txt /local/directory/Copy File with Custom Name
Rename the file during transfer:
scp localfile.txt user@remote:/path/newname.txtCopy Multiple Files
Transfer multiple files at once:
scp file1.txt file2.txt file3.txt user@remote:/destination/scp Command Manual / Help
We can use man and info command to see the manual page of scp command. scp command also have --help option to show list of options.
To open man page for scp command we can use command below. To exit man or info page you can press q.
man scpTo open info page for scp command we can use command below.
info scpTo open help page from scp command we can run command below.
scp --helpscp Command Source Code
You can find scp command source code from the following repositories:
Related Linux Commands
You can read tutorials of related Linux commands below:
Summary
In this comprehensive tutorial, we’ve covered the essential aspects of using scp for secure file transfer over SSH. scp is a fundamental tool for system administrators and developers who need to securely transfer files between systems.
Key takeaways:
scpprovides secure file transfer using SSH encryption- Supports both key-based and password authentication
- Can transfer files locally to remote, remote to local, or between remote hosts
- Essential options include
-r(recursive),-p(preserve attributes), and-P(port) - Always use SSH keys for better security in production environments
- Consider
rsyncfor large files or frequent synchronization needs
Visit our Linux Commands guide to learn more about using command line interface in Linux.