Linux Server

Learn to use SCP Command in Linux (with Examples)

The scp command in Unix is used to copy files securely between remote hosts without establishing an FTP session or even logging in to the remote system. In order to transfer data, the scp command syntax uses SSH, so authentication is required. The files and passwords exchanged with the scp command in linux are encrypted, so anyone snooping on the network cannot view them. This is unlike rcp or FTP, and this article seeks to show you how to use scp command in linux.

Files transmitted between Unix or Linux systems can be encrypted with the SCP Command in Linux (Secure Copy). Cp is a safer alternative to copy (copy). Encrypted connections are established over SSH (Secure Shell) using scp command, The data is still protected, even if it is intercepted with scp syntax. Keep reading to see how to use scp.

Syntax SCP Command

The CLI environment should be familiar to scp Linux administrators. The GUI mode is not commonly found on Linux servers, and Linux administrators may find SSH the most convenient method to remotely manage servers and not the scp usage.

In addition to SSH, SCP is also built-in. A secure copy of a file between two servers can be accomplished with SCP. File and directory copies between two locations can be made using SCP (secure copy), a command-line utility. SCP allows for the following operations:

· To remote systems from your local system.

· To local systems from remote ones.

· Your local system and two remote systems.

When processing an SCP command to transfer a file, both the files and the passwords are encrypted to prevent snoopers from getting sensitive information. CLI experience is highly recommended for Linux administrators, and it is uncommon to find GUI modes for Linux servers. Linux administrators may find that SSH is the most popular method for managing servers via a remote, secure connection. SCP commands are built into SSH.

Getting Started

scp-vIt sends debugging messages about the progress of scp and ssh. This helps track down problems with connections, authentication, and configuration.
scp –sTo use an encrypted connection, you must use the following program. You must know how to use ssh(1) options.
scp –pAccurately preserves file access times, modification times, and modes.
scp –qIt turns off the progress indicator.
scp –PDetermines the port on the remote server to use.
scp –rIt copies an entire directory recursively.
~/It stands for the user or home directory
*Specify a string of text

We’ll first review the basic scp example syntax for the scp command before learning how to use it. The syntax for the scp command is as follows:

“scp [OPTION] [[email protected]]SRC_HOST:]file1 [[email protected]]DEST_HOST:]file2”

In this scp command in Linux example, the ‘Option’ field, you need to add any known scp syntax, such as ssh configuration, cipher, ssh port, recursive copy, limit, etc. The ‘[[email protected]]SRC_HOST:]file1’ refers to the source file, and the other ‘[[email protected]]DEST_HOST:]file2’ refers to the destination file.

The path to local files should be specified as a relative or absolute path, but the host and user should be specified for remote files. This scp command example offers many options for adjusting the program’s behavior, and these are the most commonly used. They are listed in the table above.

The scp command needs an ssh key or password for authentication on the remote system to transfer data over ‘ssh.’ Using a colon (:) distinguishes local from remote locations in SCP. The source file and target system must allow reading and writing on the same level for you to be able to copy files.

Make sure you don’t copy files that have the same name and location on both systems because scp overwrites files without warning. The scp command in ubuntu should be run within a screen or tmux session to transfer large files.

File copy command

The scp command’s main function is to copy local files to the remote system. The following scp command to copy file can be used to move a file from a local to remote system:

“scp file.txt [email protected]:/remote/directory”

This command copies a file named ‘file.txt’ from one server to another, identifies a user on the remote server by ‘remote_username,’ and sets the server’s IP address to ‘10.10.0.2’. A path to the destination directory is provided by ‘/remote/directory’. You will copy the file to the remote user’s home directory if no remote directory or scp folder is specified. The transfer process will begin after you enter the user password.

Using a remote location as a source and a local location as the destination, one can copy a file from a remote system to a local system. You can run the following command at 10.10.0.2 to copy a file named file.txt from a remote server:

“scp [email protected]:/remote/file.txt /local/directory”

Altering file names

When the destination location does not contain the filename, the copied file will have the original name. It is necessary to specify the new file name if you want to save the file under another name:

“scp file.txt [email protected]:/remote/directory/newfilename.txt”

As with copying files, a directory can be copied via the same command. Recursive will require the ‘-r ‘ flag. Use the ‘-r ‘ option to copy a directory from a local system to remote one:

“scp -r /local/directory [email protected]:/remote/directory”

Getting scp process information

By default, the SCP command does not require parameters. There will not be any visible results until the process has been completed or an error has occurred. The “-v” option can be used to display debug information. Debugging problems with connections, authentication, and configuration can be done by using this option.

[email protected] ~/Documents $ scp -v Label.pdf [email protected]@202.x.x.x:.”

If you need help with this, you can use the “-p” parameter. The computer will display the estimated time and the speed of the connection. The original files are shown along with modification times, access times, and modes too.

[email protected] ~/Documents $ scp -p Label.pdf [email protected]@202.x.x.x:.”

Speeding up file transfer

The “-C” parameter can help to speed up your scp file transfer; your files will be compressed in transit using this parameter. This is unique because compression takes place only over the network, and the file will be restored to its original size once it has reached the destination server.

[email protected] ~/Documents $ scp -pv messages.log [email protected]:.”

Encrypting files

SCP encrypts files using “AES-128” by default. For encrypting it, you can change the cipher using the “-c” parameter. Below is an example.

“#scp -c 3des Label.pdf [email protected]:.”

Controlling bandwidth usage

Alternatively, you could use the “-l” parameter. The “-l” parameter limits the number of bytes transferred. You will find it helpful if you are automated scripting a more significant number of files but don’t want to use SCP to drain bandwidth.

“# scp -l 400 Label.pdf [email protected]:.”

The “-l” parameter’s value of 400 represents a bandwidth limit of 50 KB/sec for the SCP process. Broadband is designated in Kilobytes per second (kbps), and eight bits are the same as one byte, unlike SCP, which counts in Kilobytes per second. This will be useful if you are automating files but don’t want to drain bandwidth with SCP.

Read More: Learn to Create or Add User in Linux using ‘useradd’ Command

Summing Up

The purpose of this guide was to teach you what the scp command-line Linux is and how you can use it to transmit an scp file securely. An alternative to FTP, which by default is inherently insecure, is advantageous. Now that you know what the Linux command scp is mainly used to do, get to exploring. A seamless command set is created for managing files between Linux machines with secure copy, supporting regular command-line and SSH functionality.

Get in Touch

Arpit Saini

He is the Director of Cloud Operations at Serverwala Cloud Data Centers Pvt Ltd and also follows a passion to break complex tech topics into practical and easy-to-understand articles. He loves to write about Web Hosting, Software, Virtualization, Cloud Computing, and much more.

Related Articles

Adblock Detected

Please consider supporting us by disabling your ad blocker