How to copy file to another machine through terminal?

Is there possibility to connect via SSH? Maybe you should consider "scp" utitlity. It's very simple, look to the manual page:

man scp

The very basic usage:

scp remote_user@remote_host:/path/to/remote/file /path/to/local/file

and vice versa:

scp /path/to/local/file remote_user@remote_host:/path/to/remote/file

To copy a non empty directory from the remote computer to your computer:

scp -r [email protected]:/home/vrc/Desktop/www /home/ourusername/Desktop

To copy a file just exclude the -r option:

scp [email protected]:/home/vrc/Desktop/file1 /home/ourusername/Desktop

To copy from your computer to the remote computer, just switch the location and destination in the previous example. For more info do man scp.


Another way you can do: ( via pem file )

If you want to use pem file and you are ROOT user:

1. root user:

sudo scp -i ~/servers/your-key.pem ~/your-local-source-path/your-local-file.txt [email protected]:/you-server-destination-path/

note the colon : between server IP and destination path.

if I can't logged in with root user, see step 2.

2. standard user:

suppose you are ubuntu user with standard privileges.

sudo scp -i ~/servers/your-key.pem ~/your-local-source-path/your-local-file.txt [email protected]:/home/ubuntu/

this will put the file in home directory. then login to remote sever with standard user. and do

sudo su

you'll switched to root user. then move the file to destination directory

mv /home/ubuntu/your-local-file.txt /you-server-destination-path/your-local-file.txt

I often encounter this problem, therefore sharing an alternative way to get the job done !