Linux command
scp 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Copy a local file to a remote host
scp [path/to/file] [user]@[host]:[path/to/destination]
Copy a file from a remote host
scp [user]@[host]:[path/to/file] [path/to/destination]
Copy a directory recursively
scp -r [path/to/directory] [user]@[host]:[path/to/destination]
Use a specific SSH port
scp -P [2222] [path/to/file] [user]@[host]:[path/to/destination]
Use a specific identity file
scp -i [~/.ssh/id_rsa] [path/to/file] [user]@[host]:[path/to/destination]
Copy with compression enabled
scp -C [path/to/file] [user]@[host]:[path/to/destination]
Preserve file attributes
scp -p [path/to/file] [user]@[host]:[path/to/destination]
Copy between two remote hosts
scp -3 [user1]@[host1]:[file] [user2]@[host2]:[destination]
说明
scp (secure copy) transfers files between hosts over SSH. It uses SSH for authentication and encryption, providing the same security as an SSH session. The colon (:) distinguishes remote paths from local paths. Files can be copied from local to remote, remote to local, or between two remote hosts. When copying directories, use -r for recursive transfer. The remote path syntax is user@host:path, where user defaults to the current username. Authentication uses SSH keys or passwords, configured through ssh_config or command-line options. Transfer progress is shown unless -q is specified. The command exits 0 on success or >0 on error.
参数
- -r
- Recursively copy directories
- -P _PORT_
- Connect to specified port on remote host
- -p
- Preserve modification times, access times, and modes
- -C
- Enable compression
- -c _CIPHER_
- Select encryption cipher
- -i _FILE_
- Identity file (private key) for authentication
- -l _KBITS_
- Limit bandwidth in Kbit/s
- -o _OPTION_
- Pass options to ssh (ssh_config format)
- -F _FILE_
- Use specified ssh config file
- -q
- Quiet mode; suppress progress meter and warnings
- -v
- Verbose mode; show debugging messages
- -B
- Batch mode; disable password prompts
- -3
- Copy between remote hosts through local host
- -4
- Force IPv4 only
- -6
- Force IPv6 only
- -S _PROGRAM_
- Use specified program for encrypted connection
FAQ
What is the scp command used for?
scp (secure copy) transfers files between hosts over SSH. It uses SSH for authentication and encryption, providing the same security as an SSH session. The colon (:) distinguishes remote paths from local paths. Files can be copied from local to remote, remote to local, or between two remote hosts. When copying directories, use -r for recursive transfer. The remote path syntax is user@host:path, where user defaults to the current username. Authentication uses SSH keys or passwords, configured through ssh_config or command-line options. Transfer progress is shown unless -q is specified. The command exits 0 on success or >0 on error.
How do I run a basic scp example?
Run `scp [path/to/file] [user]@[host]:[path/to/destination]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -r do in scp?
Recursively copy directories