Copy files / folders via secure file transfer protocol ( scp ) Command in Linux
The SCP is secure and managed file transfer protocol for files or folders from the local system to a remote host or from a remote system to the local host. scp command usage SSH protocol in back-end to copy files securely through encrypted data transfer and authentication. So it is the best way to copy files or folders to or from remote host with this command.
Most of Linux System there is not available graphical environment, so default graphical scp not available on the system, In GNOME Environment , you can get in Menu there will be Places ==> Connect to Server in Nautilus and Choose SSH .
Here I trying to explain scp usage with different option .
General Syntax of SCP
scp source_path_of_file_folder [remote_user@]remote_host:/file_system_location
Remote server location as well as file system writes in the format like [remote_user@]remote_host:/file_system_location . Here [remote_user@] is optional, because of if you are not mention in the command, the current local will be invoked the command and then in command you should mention remote host and file where will be copy in the file system.Before the sync of files , it authenticate the user with scp server .
Copy files from the local to remote user host system
[[email protected]~]# scp techtransit.zip [email protected]:.
Here in this above command i have logged in from sachin user and want to copy in to other host machine through another user techtransit_user on the home directory that will on other host /home/techtransit_user .
Now i am explaining through root account.
[[email protected]~]# scp /opt/techtransit.zip 172.24.25.10:/tmp
Here i am logged in from root user and i want to copy file techtransit.zip from /opt directory to other host tmp directory on root account. In above command i have not given root user this will invoked by local user logged in account and copy the file into tmp directory.
Copy files from the remote user host system to the local system
We can copy files from a remote host account on a local machine with scp. See below command and explanation .
[[email protected]~]# scp 172.24.25.10:/tmp/techtransit.zip /home/techtransit
Here in the above command , we are copying techtransit.zip file from tmp directory from remote system ( 172.24.25.10) to local system directory of /home/techtransit .
scp -r : Copy whole directory structure recursively
We can send whole directory and it’s files to remote host and also from remote host to local machine as we have discussed in above part , only we need to use –r option .
[[email protected] ~] # scp -r techtransit [email protected]:.
scp -P : Copy on different remote host port
If your remote host using different port in SSH , then you need to give port manually by –P option . By default it is taking 22 port of ssh protocol .so scp or ssh, we are using directly without option .
[[email protected] ~] #scp -P 4433 techtransit.zip remote_user@:172.24.25.10/directory
Here in above part remote server using different port like 4433 , so we have take after –P option 4433 .
scp -c : SCP through different Ciphers for performance
In the linux system there is different number of ciphers available for performance as well as security concern. Different linux machine system using different ciphers algorithm for SSH .Below is available on machine ciphers list and the default is aes128-cbc .
By default aes128-cbc is cipher algorithm used to encrypt file in transfer .If you want to change cipher in transfer for performance or security you can use others .Here is option –c for change algorithm .
[[email protected] ~]# scp -c arcfour techtransit.zip remote_user@:172.24.25.10/directory
The arcfour is cipher algorithm , which is having good performance speed compare to other . Different algorithm having different features.
scp -i : Copy through identity private key file.
Most of the cloud server provided login through pem or key file like private . So here is option to copy file through scp .
scp -i techtransit.pem filename [email protected]_PUBLIC_IP:/
Here i am shown example of my pem key with option -i.