How to copy files using SCP in the terminal for remote file transfer?

Welcome to CodeNet, To copy a file to another machine through the terminal, you can use the scp command. scp (secure copy) is a command-line tool for securely transferring files between computers over a network.

Here’s how you can use scp to copy a file from one machine to another:

  1. Open a terminal window on the machine where the file you want to copy is located.
  2. Use the scp command to copy the file to the destination machine. The syntax for the scp command is:
scp [options] source_file destination_file

Replace source_file with the file you want to copy, and destination_file with the location where you want to copy the file. The destination_file can be a local file path or a remote machine address in the format of [username@]host:[path].

For example, to copy a file named file.txt from the local machine to a remote machine with the IP address 192.168.0.2, you would use the following command:

scp file.txt user@192.168.0.2:/home/user/

This would copy file.txt to the /home/user/ directory on the remote machine.

  1. When you run the scp command, you may be prompted for a password. Enter the password for the remote machine when prompted.
  2. Wait for the file transfer to complete. Once the transfer is complete, you should see a message indicating that the file transfer was successful.

That’s it! You’ve successfully copied a file to another machine through the terminal using scp. Note that scp uses SSH for secure file transfers, so you need to have SSH access to the remote machine to use scp.

Leave a Comment

Scroll to Top