SCP Command in Linux/Unix with ExamplesIntroduction to SCP CommandSCP stands for Secure Copy Protocol. In the Linux system, the SCP command copies files between many servers securely. It permits secure file transferring between the remote host and the local host or two remote hosts. It applies the same security and authentication as it's used in the SSH (Secure Shell) protocol. The SCP command is known for its pre-installed availability, security, and simplicity. Secure copy protocol is a command-line utility that permits the user to copy directories and files securely between two different locations, usually between Linux or Unix systems. The protocol guarantees the file transmission is encrypted to avoid anyone with wrong intentions from stealing sensitive information. In other words, we can say that the SCP command is a substitute for the copy (cp) command. Before we start For data transfer, the SCP command depends on ssh, so it needs a password or ssh key to authenticate over the remote systems. On the target system and source file, we must have at least write permission and read permission, respectively, to copy files. The colon is how the SCP command distinguishes between remote and local locations. We need to be careful while copying files that have the same location and name on both systems; the SCP command will overwrite those files without any warning. It's suggested to execute the SCP command in a tmux or screen session when sending large files. Options of the SCP CommandWe can add several SCP commands options to any command to speed up and customize the process. Options are included as aspects right after scp.All options have a single character, a short form, and a descriptive, longer equivalent.
Syntax of SCP CommandBefore using the SCP command, let's begin with the common syntax. The syntax of the SCP command takes the below form: Where,
Local files must be specified using a relative or absolute path, while the names of the remote file must include a host and user specification. Examples of SCPCopy directories and files between two different systems using SCPCopy a local file using the SCP command We need to execute the below command to copy any file from a local system to a remote system: Where empty.txt is the file name we wish to copy, remote_username is the remote server user, and 10.10.0.2 is the IP address of the server. The /remote/directory is the directory path we wish to copy our file to. If we do not specify any remote directory, our file will copy to the home directory of the remote user. We will be asked to type our password, and the copy process will begin.
Copy a remote file to the local system with the scp command We will use the remote position as a source and the local position as the destination to copy any remote file to the local system. For instance, to copy a file called empty.txt from any remote server along with the 10.10.0.2 IP address, execute the below command: We will be promoted to enter our user password if we have not set the passwordless SSH login on the remote machine. Copy any file between two different remote systems with the scp command When using the scp command, we do not need to login to any of the servers to send files from one remote system to another, unlike rsync. The below command will copy the /empties/empty.txt file from the ;remote1.com ;remote host to the /empties directory on the ;remote2.com ;remote host: We will be asked to enter our passwords for remote accounts. Our data will be directly transferred between these remote hosts. We will use the -3 option for routing the traffic from the machine over which the command is permitted: Next TopicWhat is the Linux Kernel |