Home » Linux Host, Ubuntu, SysAdmin » System Administration, Security » How to copy files from one Linux machine to another using scp, rsync and ssh ?

How to copy files from one Linux machine to another using scp, rsync and ssh ?

To copy files from one machine to another machine using ssh, you can do that in 3 ways,


scp copies files between hosts on a network. It uses ssh(1) for data transfer, and uses the same authentication and provides the same security as ssh(1). scp will ask for passwords or passphrases if they are needed for authentication.

$ mkdir local_folder
$ cd local_folder
 $ echo "hello copy world" > this_is_test_file.txt

Using below command you can now copy the file we created to remote machine,

 $ scp this_is_test_file.txt remote_username@remote_user_ip:/home/remote_username/Desktop

You can copy the local folder and all its contents using below command,

 $ scp -r local_folder remote_username@remote_user_ip:/home/remote_username/Desktop 

You can also copy the folder and its content from remote machine to your local machine as,

 $ scp -r remote_username@remote_user_ip:/home/remote_username/Desktop/remote_folder local_folder


Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be copied. It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use.

$ rsync -av -e "ssh" local_folder remote_username@remote_user_ip:/home/remote_username/Desktop

Remote Mount using sshfs

SSHFS (Secure SHell FileSystem) is a file system for Linux (and other operating systems with a FUSE
implementation, such as Mac OS X or FreeBSD) capable of operating on files on a remote computer using
just a secure shell login on the remote computer

For copying using sshfs, we need to first mount the remote folder to local machine which you can do by following “How to transfer large file to remote server over ssh with unstable internet” once we mount remote folder to local folder, then we can just use cp to copy like we use for local copy of files.

 $ cp -r local_folder remote_mounted_folder 
COPY One File to another in C using...
COPY One File to another in C using fgetc and fputc function

Leave a Comment

Sign up to our newsletter!