Skip to main content

Use scp to copy a file and a directory from one machine to another:

Use scp to copy a file and a directory from one machine to another:

Copying a Single File

  1. Open a terminal on the source machine (Machine A).

  2. Use the scp command to copy the file to the destination machine (Machine B).


  1. scp /path/to/source/file user@machineB:/path/to/destination/
    • /path/to/source/file: The path to the file you want to copy on Machine A.
    • user@machineB: The username and hostname or IP address of Machine B.
    • /path/to/destination/: The path to the destination directory on Machine B.

Copying a Directory

  1. Open a terminal on the source machine (Machine A).

  2. Use the scp command with the -r option to copy the directory to the destination machine (Machine B).


  1. scp -r /path/to/source/directory user@machineB:/path/to/destination/
    • -r: Option to copy directories recursively.
    • /path/to/source/directory: The path to the directory you want to copy on Machine A.
    • user@machineB: The username and hostname or IP address of Machine B.
    • /path/to/destination/: The path to the destination directory on Machine B.

Example

Copying a File

Suppose you want to copy example.txt from /home/userA/documents on Machine A to /home/userB/backup on Machine B:


scp /home/userA/documents/example.txt userB@machineB:/home/userB/backup/

Copying a Directory

Suppose you want to copy the entire documents directory from /home/userA/documents on Machine A to /home/userB/backup on Machine B:


scp -r /home/userA/documents userB@machineB:/home/userB/backup/

Conclusion

These commands will allow you to copy a file or a directory from Machine A to Machine B using scp. Make sure to replace the placeholders with the actual paths and usernames relevant to your setup.