The scp (secure copy) command is used in Linux and Unix-like operating systems to securely transfer files and directories between a local host and a remote host over a Secure Shell (SSH) connection. It provides a way to copy files between hosts in a secure and efficient manner. Here's how to use the scp command:
scp [options] source destination
options: Various options to control the behavior of the scp command.
source: The file or directory you want to copy from the local host.
destination: The target location on the remote host.
Copying a File from Local to Remote:
scp file.txt remote_user@remote_host:/remote/directory/
file.txt: The local file you want to copy.
remote_user: The username on the remote host.
remote_host: The hostname or IP address of the remote host.
/remote/directory/: The destination directory on the remote host.
Copying a File from Remote to Local:
scp remote_user@remote_host:/remote/file.txt /local/directory/
Copying a Directory Recursively:
scp -r local_directory/ remote_user@remote_host:/remote/directory/
-r: Recursively copy the directory and its contents.
Copying with Specific SSH Key:
scp -i /path/to/private/key.pem file.txt remote_user@remote_host:/remote/directory/
-i /path/to/private/key.pem: Specifies the private key file for authentication.
Copying with Port Specification:
scp -P 2222 file.txt remote_user@remote_host:/remote/directory/
-P 2222: Specifies the SSH port (replace 2222 with the desired port number).
Copying from Remote to Local with Progress Display:
scp -r remote_user@remote_host:/remote/directory/ local_directory/ --progress
--progress: Displays the progress of the file transfer.
Additional Options
-v: Verbose mode, displays detailed output.
-q: Quiet mode, suppresses non-error messages.
-p: Preserves modification times, access times, and modes from the original file.
-C: Compresses data during transfer to improve speed.
Remember to replace placeholders like remote_user, remote_host, file.txt, local_directory, and /remote/directory/ with actual values.
Note: For scp to work, SSH must be installed on both the local and remote hosts, and you must have proper permissions to access the source and destination files or directories.
Always ensure that you have the necessary permissions and that you're using the correct paths and addresses when using the scp command.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.