What is scp Linux command?
Securely transfer files between a local and remote host with the scp command in Linux. Encrypted data transmission for enhanced security.
scp Syntax:
scp Options:
Option | Description |
---|---|
-r | Recursively copy entire directories |
-P | Specify the port to connect to on the remote host |
-p | Preserves the modification and access times, as well as the permissions of the source-file in the destination-file |
-q | Do not display the progress meter |
-C | Enable compression during the transfer |
-i | Specify the identity file (private key) for public key authentication |
Parameters:
Parameter | Description |
---|---|
source | Specifies the file or directory to be copied |
destination | Specifies the destination path for the file(s) |
scp Command Usage Examples:
Copy a Local File to a Remote Server
Copies a local file to a remote server using SCP.
Copy a Remote File to a Local Machine
Retrieves a file from a remote server and copies it to a local directory.
Copy an Entire Directory to a Remote Server
Recursively copies an entire directory from local to remote server.
Copy a Remote File with a Specific Port
Copies a file from a remote server using a specific port.
Copy Multiple Files from a Remote Server
Copies multiple files from a remote server to a local directory.
How do I use scp in Linux?
To use the scp command in bash, execute the following command:
How can I copy a directory with scp?
To copy a directory using scp, use the -r
flag to recursively copy all files and directories within the specified directory. Here’s an example:
How do I specify a different port with scp?
To specify a different port with scp, use the -P
flag followed by the port number. Here’s an example:
How to transfer a file from a remote server to a local machine using scp?
To transfer a file from a remote server to a local machine with scp, switch the positions of the source and destination paths. Here’s an example:
How do I preserve file attributes like permissions and timestamps when using scp?
To preserve file attributes like permissions and timestamps during file transfer, use the -p
flag with scp. Here’s an example:
How to display the progress of a file transfer with scp?
To display the progress of a file transfer with scp, use the -v
flag for verbose output. This will show the progress and additional information during the transfer. Here’s an example:
How do I use a specific SSH private key with scp?
To use a specific SSH private key with scp, use the -i
flag followed by the path to the private key file. Here’s an example:
Applications of the scp command
- Securely copy files and directories between local and remote hosts
- Transfer files and data over a secure shell (SSH) connection
- Copy files between two remote hosts by specifying both the source and destination in the scp command
- Securely copy files with encryption to protect sensitive data during transfer
- Backup files and directories from a local system to a remote server
- Copy files from a remote server to a local system
- Transfer files using different authentication methods supported by SSH