How to write an scp command in terminal

SCP is a command from SSH toolset used to copy files from one host to another. Oftenly it is used to copy file from your local PC to the server on which you have SSH access, or reversly from server to your local PC.

How to write a command:

scp /path/to/file.txt [email protected]:/path/on/server/to/

Will copy file.txt from your pc to server on IP 8.8.8.8, by accessing ssh for root user. You should know a password of root user, or have you public key installed to /root/.ssh/authorized_keys on server.

Reverse operation - copy from server to local pc:

scp [email protected]:/path/on/server/to/file.txt /path/on/local/machine/

How to write scp command to copy folder📂

To copy folder from your host to server:

scp -r /path/to/folder [email protected]:/path/on/server/

WIll copy folder and nested files to /path/on/server/.

⚠ If your folder has a lot of small files inside we strongly recommend not use SCP, but use tar + ssh command to speed process up:

tar -czf - /path/to/folder | ssh [email protected] tar -xzf - -C /path/on/server/

It is faster equivalent for above command. Why: because how long does a server transfer takes depends not on size, but on files count. Here we just tar filez with simple GZIP compression to one stream and pass this stream over SSH stdio.

How to copy multiple files from server to your computer🗄➡💻

Use this command for speed optimized copy:

ssh [email protected] tar -czf - /path/to/folder | tar -xzf - -C /path/on/server/

#scp #ssh
menu 10
Ivan Borshchov profile picture
Nov 17, 2020
by Ivan Borshchov

Best related

Other by Ivan Borshchov