scpCopy files to and from servers over SSH
scp copies files between your machine and a server (or between two servers) over SSH, with the same keys, ports and ~/.ssh/config as ssh. It's the quickest way to push a tarball or pull a log; for big trees or repeated syncs use rsync instead.
scp [-r] [-p] [-P PORT] [-i KEY] [-J JUMP] SOURCE... [USER@]HOST:DEST (or HOST:SRC LOCAL_DEST)Push a build to an app server, then pull its error log back to your machine for a closer look.
scpSecure copy. Opens an SSH connection and transfers the files inside it.
scp starts ssh as a subprocess to the remote host, so authentication, host key checks, ProxyJump and every ~/.ssh/config setting apply unchanged. Since OpenSSH 9.0 scp speaks the SFTP protocol by default: it asks the server for the sftp subsystem and then opens, writes and closes files with SFTP requests. The old behaviour (-O) instead ran 'scp -t' or 'scp -f' in a remote shell and streamed files with a simple rcp-style protocol, which let the remote shell expand wildcards and caused several security bugs. Either way scp copies every file completely each time: there is no comparison with what's already at the destination, no resume after an interruption and no delete of extra files. Paths with spaces need quoting for the remote side too. With -3, a copy between two remote hosts goes through your machine instead of directly between them.
-rCopy directories recursively-pPreserve modification times and modes-P PORTRemote SSH port (capital P)-i KEYIdentity (private key) file-J user@bastionGo through a jump host-CCompress during transfer (helps on slow links, text files)-l KBITLimit bandwidth in Kbit/s-qQuiet: no progress meter-3Copy between two remote hosts through the local machine-OUse the legacy SCP protocol instead of SFTP (old servers)-vVerbose SSH debug outputscp -p 2222 file host:/tmp/In scp, -p means preserve times; the port option is capital -P (the opposite of ssh).
scp -P 2222 file host:/tmp/scp file host (forgetting the colon)Without a colon both sides are local, so scp silently creates a local file called 'host'.
scp file host: # or host:/path/Using scp to redeploy a big directory again and againscp re-sends every file in full and never deletes removed files, so it's slow and leaves stale files behind.
rsync -az --delete dist/ host:/var/www/site/Restarting a huge scp from zero after a dropped connectionscp has no resume; the partial file is just overwritten.
rsync --partial --progress big.iso host:/data/ # or sftp reputTry these on a Linux machine of your own. Each task has a hint and a solution.
There's no remote host in the sandbox, but scp can copy locally. Copy ~/app to /tmp/app-copy recursively, preserving times.
Write the command that downloads /var/log/nginx/error.log from 10.0.2.15 (user ubuntu, SSH port 2222) into the current directory.
Write the command that uploads ~/app.tar.gz to /tmp on 10.0.2.15 through the jump host bastion.devops-lab.io.
scpCopy files to and from servers over SSH
scp copies files between your machine and a server (or between two servers) over SSH, with the same keys, ports and ~/.ssh/config as ssh. It's the quickest way to push a tarball or pull a log; for big trees or repeated syncs use rsync instead.
scp [-r] [-p] [-P PORT] [-i KEY] [-J JUMP] SOURCE... [USER@]HOST:DEST (or HOST:SRC LOCAL_DEST)Push a build to an app server, then pull its error log back to your machine for a closer look.
scpSecure copy. Opens an SSH connection and transfers the files inside it.
scp starts ssh as a subprocess to the remote host, so authentication, host key checks, ProxyJump and every ~/.ssh/config setting apply unchanged. Since OpenSSH 9.0 scp speaks the SFTP protocol by default: it asks the server for the sftp subsystem and then opens, writes and closes files with SFTP requests. The old behaviour (-O) instead ran 'scp -t' or 'scp -f' in a remote shell and streamed files with a simple rcp-style protocol, which let the remote shell expand wildcards and caused several security bugs. Either way scp copies every file completely each time: there is no comparison with what's already at the destination, no resume after an interruption and no delete of extra files. Paths with spaces need quoting for the remote side too. With -3, a copy between two remote hosts goes through your machine instead of directly between them.
-rCopy directories recursively-pPreserve modification times and modes-P PORTRemote SSH port (capital P)-i KEYIdentity (private key) file-J user@bastionGo through a jump host-CCompress during transfer (helps on slow links, text files)-l KBITLimit bandwidth in Kbit/s-qQuiet: no progress meter-3Copy between two remote hosts through the local machine-OUse the legacy SCP protocol instead of SFTP (old servers)-vVerbose SSH debug outputscp -p 2222 file host:/tmp/In scp, -p means preserve times; the port option is capital -P (the opposite of ssh).
scp -P 2222 file host:/tmp/scp file host (forgetting the colon)Without a colon both sides are local, so scp silently creates a local file called 'host'.
scp file host: # or host:/path/Using scp to redeploy a big directory again and againscp re-sends every file in full and never deletes removed files, so it's slow and leaves stale files behind.
rsync -az --delete dist/ host:/var/www/site/Restarting a huge scp from zero after a dropped connectionscp has no resume; the partial file is just overwritten.
rsync --partial --progress big.iso host:/data/ # or sftp reputTry these on a Linux machine of your own. Each task has a hint and a solution.
There's no remote host in the sandbox, but scp can copy locally. Copy ~/app to /tmp/app-copy recursively, preserving times.
Write the command that downloads /var/log/nginx/error.log from 10.0.2.15 (user ubuntu, SSH port 2222) into the current directory.
Write the command that uploads ~/app.tar.gz to /tmp on 10.0.2.15 through the jump host bastion.devops-lab.io.