To use scp
(secure copy) to transfer files from your laptop to an Ubuntu machine (or vice versa) over SSH, follow these steps:
- 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).
- On Ubuntu: You can open a terminal by pressing
- Run the
scp
Command: - 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 192.168.1.100
, you would run:
scp file.txt ubuntu@192.168.1.100:/home/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@192.168.1.100:/home/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@192.168.1.100:/path/to/file.txt /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@192.168.1.100:/home/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@192.168.1.100
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.