How to write an SCP command in terminal

#StandWithUkraine
Today, 4th December 2022, Ukraine is still bravely fighting for democratic values, human rights and peace in whole world. Russians ruthlessly kill all civilians in Ukraine including childs and destroy their cities. We are uniting against Putin’s invasion and violence, in support of the people in Ukraine. You can help by donating to Ukrainian's army.

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

How to write a command:

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

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

Reverse operation - copy from server to local pc:

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

How to write SCP command to copy the folder📂

To copy folder between hosts:

scp -r /path/to/folder [email protected]8.8.8.8:/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 the process up:

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

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

#scp #ssh
10
Ivan Borshchov profile picture
Nov 17, 2017
by Ivan Borshchov
Did it help you?
Yes !
No

Best related