How to transfer files from your laptop to an Ubuntu machine (or vice versa)?

Posted by

To use scp (secure copy) to transfer files from your laptop to an Ubuntu machine (or vice versa) over SSH, follow these steps:

  1. Open a Terminal:
    • On Ubuntu: You can open a terminal by pressing Ctrl + Alt + T or by searching for “Terminal” in the applications menu.
    • On your laptop (assuming it’s running Windows or macOS): Open the command prompt (Windows) or terminal (macOS).
  2. Run the scp Command:
  3. The basic syntax for scp is:
scp [options] source destination
  • source: The file or directory you want to copy.
  • destination: The target location where you want to copy the file or directory.

For example, to copy a file named file.txt from your laptop to the /home/ubuntu directory on the Ubuntu machine with the IP address, you would run:

scp file.txt ubuntu@

You will be prompted to enter the password for the ubuntu user on the Ubuntu machine.

3.Copying Directories:

If you want to copy an entire directory and its contents, you can use the -r option to recursively copy files:

scp -r /path/to/directory ubuntu@

    4. Copying from Ubuntu to Laptop:

    To copy files from the Ubuntu machine to your laptop, you reverse the source and destination:

    scp ubuntu@ /local/destination/path

    5. Specifying a Custom SSH Key (Optional):

    If you’re using SSH keys for authentication instead of passwords, you can specify the private key file using the -i option:

    scp -i /path/to/private_key file.txt ubuntu@

    6.Other Options:

    • -P: Specifies the port to connect to on the remote host.
    • -v: Verbose mode. Helpful for troubleshooting.

      Remember to replace ubuntu@ with the appropriate username and IP address of your Ubuntu machine, and adjust file paths as necessary.

      Once the scp command is executed, the file(s) will be securely copied over SSH to the specified destination.

      Inline Feedbacks
      View all comments
      Would love your thoughts, please comment.x