Using scp to Copy to/from a Remote Server with SSH

Published on Author craigzearfossLeave a comment

scp stands for secure cp (copy), which means that you can copy files across an ssh connection that will be encrypted, and therefore secured. With it you can copy files from or to a remote server. You can even copy files from one remote server to another remote server.


scp [[user@]from-host:]source-file [[user@]to-host:][destination-file]


from-host the name or IP of the host where the source file is, this can be omitted if the from-host is the host where you are actually issuing the command
user the user which has the right to access the file and directory that is supposed to be copied in the case of the from-host and the user who has the rights to write in the to-host
source-file the file or files that are going to be copied to the destination host, it can be a directory but in that case you need to specify the -r option to copy the contents of the directory
destination-file the name that the copied file is going to take in the to-host, if none is given then all of the copied files are going to maintain the same names


-p Preserves the modification and access times, as well as the permissions of the source-file in the destination-file
-q Do not display the progress bar
-r Recursive, so it copies the contents of the source-file (directory in this case) recursively
-v Displays debugging messages


scp *.txt

This will copy all files with .txt extension to the directory /home/user in the host

scp -r miguel@ miguel@

This is going to recursively copy all files from miguel’s Home directory on host to his Home directory in host.

Note: To use this command you need to have open-ssh installed in the hosts.

Leave a Reply

Your email address will not be published. Required fields are marked *