Difference between revisions of "Scp"
(51 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | Secure copy | + | {{lc}} |
+ | [[wikipedia:Secure copy]] (<code>scp</code>) is a means of securely transferring computer files between a local host and a remote host or between two remote hosts. scp implements a [[progress]] bar to estimate transfers. | ||
+ | http://man7.org/linux/man-pages/man1/scp.1.html | ||
+ | |||
+ | scp help | ||
+ | usage: scp [-346ABCpqrTv] [-c cipher] [-F ssh_config] [-i identity_file] | ||
+ | [-J destination] [-l limit] [-o ssh_option] [-P port] | ||
+ | [-S program] source ... target | ||
+ | |||
+ | == Examples == | ||
+ | scp your_username@your_server:/tmp/FILE ./ | ||
+ | scp -r your_username@your_server:/path/to/your/remote/folder ./ | ||
+ | scp -r [[-P]] 1234 your_username@your_server:/path/to/your/remote/folder ./ | ||
+ | |||
+ | scp your_username@your_server:/tmp/FILE ./ | ||
+ | USERNAME@SERVER's password: | ||
+ | Could not chdir to home directory /home/USERNAME: No such file or directory | ||
+ | protocol error: mtime.sec not present | ||
+ | |||
+ | scp USERNAME@SERVER:/tmp/your_folder ./ | ||
+ | scp: /tmp/your_folder: not a regular file | ||
+ | |||
+ | [[scp -r]] USERNAME@SERVER:/tmp/your_folder ./ | ||
+ | scp: /tmp/your_folder/your_file: Permission denied | ||
+ | |||
+ | == Security == | ||
+ | According to [[OpenSSH]] developers in April 2019 the scp protocol is outdated, inflexible and not readily fixed; they recommend the use of more modern protocols like <code>[[Secure file transfer program|sftp]]</code> and <code>[[rsync]]</code> for file transfer.<ref>{{cite web|url=https://www.openssh.com/txt/release-8.0|title=OpenSSH 8.0|work=OpenSSH Release Notes|date=17 April 2019}}</ref> | ||
+ | |||
+ | [[OpenSSH 8.3]] May 2020 | ||
+ | scp(1): when receiving files, scp(1) could be become desynchronised if a <code>[[utimes]] (2)</code> system call failed. This could allow file contents to be interpreted as file metadata and thereby permit an adversary to craft a file system that, when copied with scp(1) in a configuration that caused utimes(2) to fail (e.g. under a <code>[[SELinux]]</code> policy or syscall sandbox), transferred different file names and contents to the actual file system layout. Exploitation of this is not likely as utimes(2) does not fail under normal circumstances. Successful exploitation is not silent - the output of scp(1) would show transfer errors followed by the actual file(s) that were received. Finally, filenames returned from the peer are (since openssh-8.0) matched against the user's requested destination, thereby disallowing a successful exploit from writing files outside the user's selected target glob (or directory, in the case of a recursive transfer). This ensures that this attack can achieve no more than a hostile peer is already able to achieve within the scp protocol. | ||
== Activities == | == Activities == | ||
− | + | * Understand the differences between <code>[[cp]], [[scp]]</code> and <code>[[rsync]]</code>: https://stackoverflow.com/questions/20244585/how-does-scp-differ-from-rsync | |
− | + | * Review security advisories related to <code>scp</code>: [[CVE]]-2019-6111<ref>https://nvd.nist.gov/vuln/detail/CVE-2019-6111</ref> related to <code>[[scp]]</code> tool and protocol allowing to overwrite arbitrary files in the scp client target directory | |
+ | * <code>[[pv]] </dev/zero | ssh REMOTE_SERVER 'cat >/dev/null'</code> | ||
+ | |||
+ | == News == | ||
+ | * [[OpenSSH 9.0]] Aug 2022 https://www.openssh.com/txt/release-9.0 switches scp from using the legacy scp/rcp protocol to using the SFTP protocol by default | ||
+ | |||
+ | == Related terms == | ||
+ | * <code>[[pscp]]</code> ([[PuTTY]]) | ||
+ | * <code>[[sftp]]</code> | ||
+ | * <code>[[jailkit]]</code> | ||
+ | * [[magic-wormhole]] | ||
+ | * [[progress]] | ||
+ | * <code>[[scp -3]]</code> | ||
+ | * [[Resume transmissions]]: <code>[[rsync]] -P or --partial --progress</code> | ||
+ | * [[uses: actions/upload-artifact]] in [[GitHub Actions]] | ||
+ | * [[GitLab CI: artifacts:]] | ||
== See also == | == See also == | ||
+ | * {{sftp}} | ||
* {{cp}} | * {{cp}} | ||
+ | * {{OpenSSH}} | ||
[[Category:networking]] | [[Category:networking]] | ||
+ | [[Category:Linux commands]] |
Latest revision as of 16:19, 31 October 2023
wikipedia:Secure copy (scp
) is a means of securely transferring computer files between a local host and a remote host or between two remote hosts. scp implements a progress bar to estimate transfers.
http://man7.org/linux/man-pages/man1/scp.1.html
scp help usage: scp [-346ABCpqrTv] [-c cipher] [-F ssh_config] [-i identity_file] [-J destination] [-l limit] [-o ssh_option] [-P port] [-S program] source ... target
Examples[edit]
scp your_username@your_server:/tmp/FILE ./ scp -r your_username@your_server:/path/to/your/remote/folder ./ scp -r -P 1234 your_username@your_server:/path/to/your/remote/folder ./
scp your_username@your_server:/tmp/FILE ./ USERNAME@SERVER's password: Could not chdir to home directory /home/USERNAME: No such file or directory protocol error: mtime.sec not present
scp USERNAME@SERVER:/tmp/your_folder ./ scp: /tmp/your_folder: not a regular file
scp -r USERNAME@SERVER:/tmp/your_folder ./ scp: /tmp/your_folder/your_file: Permission denied
Security[edit]
According to OpenSSH developers in April 2019 the scp protocol is outdated, inflexible and not readily fixed; they recommend the use of more modern protocols like sftp
and rsync
for file transfer.[1]
OpenSSH 8.3 May 2020
scp(1): when receiving files, scp(1) could be become desynchronised if a utimes (2)
system call failed. This could allow file contents to be interpreted as file metadata and thereby permit an adversary to craft a file system that, when copied with scp(1) in a configuration that caused utimes(2) to fail (e.g. under a SELinux
policy or syscall sandbox), transferred different file names and contents to the actual file system layout. Exploitation of this is not likely as utimes(2) does not fail under normal circumstances. Successful exploitation is not silent - the output of scp(1) would show transfer errors followed by the actual file(s) that were received. Finally, filenames returned from the peer are (since openssh-8.0) matched against the user's requested destination, thereby disallowing a successful exploit from writing files outside the user's selected target glob (or directory, in the case of a recursive transfer). This ensures that this attack can achieve no more than a hostile peer is already able to achieve within the scp protocol.
Activities[edit]
- Understand the differences between
cp, scp
andrsync
: https://stackoverflow.com/questions/20244585/how-does-scp-differ-from-rsync - Review security advisories related to
scp
: CVE-2019-6111[2] related toscp
tool and protocol allowing to overwrite arbitrary files in the scp client target directory pv </dev/zero | ssh REMOTE_SERVER 'cat >/dev/null'
News[edit]
- OpenSSH 9.0 Aug 2022 https://www.openssh.com/txt/release-9.0 switches scp from using the legacy scp/rcp protocol to using the SFTP protocol by default
Related terms[edit]
pscp
(PuTTY)sftp
jailkit
- magic-wormhole
- progress
scp -3
- Resume transmissions:
rsync -P or --partial --progress
- uses: actions/upload-artifact in GitHub Actions
- GitLab CI: artifacts:
See also[edit]
sftp
,sftp chroot configuration
, Filezilla, Core FTP,sshfs
,internal-sftp
,sshd_config
, SFTP protocol, Secure file transfer program (sftp)cp
,dd
,sftp
,scp
,rsync
,casync
,mv
,fio
,ln
,docker cp, kubectl cp
,minikube cp
,multipass transfer
,Copy-Item
,Xcopy
- OpenSSH (changelog):
/etc/ssh/sshd_config
|/etc/ssh/ssh_config
|~/.ssh/
|openSSL | sshd logs
|sftp
|scp
|authorized_keys
|ssh-keygen
|ssh-keyscan
|ssh-add
|ssh-agent
|ssh
|Ssh -O stop
|ssh-copy-id
|CheckHostIP
|UseKeychain
, OpenSSF
Advertising: