What is SCP Command? How to use SCP Command in Linux
To securely copy files from local to remote and vice versa on Linux, you will need to use SCP Command. So what is SCP Command and how to use this command in Linux? Let's find out with TipsMake in the following article.
What is SCP Command?
SCP stands for Secure Copy Protocol, so we can understand that SCP Command is a command used to securely copy files and folders between computers, including transferring data between the local machine and a remote server, or between two remote servers. This command uses the SSH (Secure Shell) protocol to encrypt data during transmission, ensuring that sensitive information is not exposed.
SCP Command Syntax
The basic syntax of the SCP command is as follows:
scp [options] [[user@]host1:]source_file_or_directory . [[user@]host2:]destination
In there:
● [options]: Additional options to adjust the behavior of the SCP command.
● [[user@]host1:]: Source server address, can be local or remote.
● source_file_or_directory: The file or directory to copy from the source server.
● [[user@]host2:]: The destination server address where the file will be copied to.
● destination: Path to the destination directory on the destination server.
Some commonly used options with the SCP command include:
What is SCP Command?
Some notes when using SCP Command
The SCP command uses SSH to move data, requiring authentication with an SSH key or password. The colon (:) distinguishes between local and remote locations. To copy files, read permissions are required on the source file and write permissions on the destination system.
Note: SCP will overwrite files with the same name without warning, so be careful. For large files, it is recommended to run SCP in a screen or tmux session to avoid losing connections.
How to use SCP Command in Linux
1. How to securely copy a file from local machine to remote machine
To securely copy a file from the local computer to a remote computer, you use a command like the following:
Using the SCP command to copy files from your local machine to a remote server, such as a VPS, makes it easy to deploy web applications. You can quickly push updated files from your development environment to your server.
For example, to copy the scp.zip file to the remote server with the root user, you use the following command:
scp /users/Hostinger/desktop/scp.zip root@162.168.1.2:/write/post
If you don't have an SSH key pair set up, you'll be prompted for a password and shown a progress bar. SCP uses the default SSH port 22, but if you have a custom port, you can add the -P option:
scp -P 2322 /users/Hostinger/desktop/scp.zip root@162.168.1.2:/writing/article
To rename a transferred file, simply specify the new name in the destination folder:
scp /users/Hostinger/desktop/scp.zip root@162.168.1.2:/writing/article/howtoscp.zip
You can also copy directories recursively using the -r command to transfer multiple files at once:
scp -r /users/Hostinger/desktop root@162.168.1.2:/write/post
Additionally, you can copy multiple files by specifying their names:
scp file1.txt file2.txt file3.txt root@
2. How to safely copy a file from a remote computer to a local computer
To transfer data from a remote system to your local machine using SCP, simply reverse the source and destination locations. This allows you to download and work with the project file offline.
For example, use the following command to pull the scp.zip file from the VPS to the local machine:
scp root@162.168.1.2:/writing/articles/SCP.zip /Users/Hostinger/Desktop
When you run this command, you will be prompted for your SSH password. If you have public key authentication set up, you will not need to enter a password.
3. How to copy files between two remote computers
SCP allows file transfers not only to or from the current server, but also between two remote Linux machines. This improves efficiency, especially when you have multiple projects on different machines, as you don't need to log into each system individually.
For example, to transfer the scp.zip file from root@162.168.1.2 to hostinger@162.168.1.1, you would use the following command:
scp root@162.168.1.2:/write/article/scp.zip hostinger@162.168.1.1:/publish
You will need the SSH password for both accounts. By default, SCP routes data directly between remote machines, but you can route it through your local computer by adding the -3 option:
scp -3 root@162.168.1.2:/write/article/scp.zip hostinger@162.168.1.1:/publish
This option is useful when experiencing network errors between systems, although it can slow down the process and does not show a progress bar.
Conclude
SCP Command is not only a powerful tool for transferring data but also ensures the security of your information during the transmission process. Through the above instructions, hopefully you have mastered how to use SCP Command in Linux to perform file copy operations effectively.
You should read it
May be interested
- Instructions for using zforce command on Linuxthe gzip command is a popular tool used to compress / decompress files in linux. tipsmake.com presents the basics of this tool in the article: some basic terminal commands in linux mint 11.
- How to limit access to su command in Linuxif you have added linux to your data center or are just using a single linux machine for your business, you need to make sure it is as secure as possible.
- 12 things Linux is easier to do in the command line than graphical softwaregraphical user interfaces (guis) were invented to make life easier for computer users, so it's very common to use them to perform most everyday tasks.
- 11 df commands in Linux (with example)with the df command in linux, you can easily check your system for details about disk space and file size. these 12 examples of df commands will show you how to do them in detail.
- How to use the Linux command line on Android with Termuxandroid is a very operating system 'capacity with more and more desktop accessibility applications. however, sometimes you want to make some things on android that can be as easy as desktop. fortunately, you can use the termux tool, which builds on the existing infrastructure and provides a command line environment that allows you to install real linux applications on your android device.
- Instructions for using find command in Linuxthe find command is one of the most important and handy commands on a linux system. as its name suggests, the command can find files on a linux pc based on a variety of conditions and variables you set.
- How to use the history command in Linuxas you spend more and more time in terminal sessions, you will constantly find new commands that make everyday tasks more efficient. the gnu history command is one of them.
- Instructions for using pstree command on Linuxpstree is a powerful and useful command to display processes running in linux. like the ps command, it shows all the processes that are currently active on your login system. the main difference is that when running the pstree command, processes are organized into tree sorting instead of lists like using the ps command.
- The dd command in Linux, How to use the dd commanddd is a command line utility for unix-like and unix operating systems, with the main purpose of converting and copying files.
- Use the Top command to see the processes running in Linuxthe top command in linux is used to display all processes running in the linux environment. this tutorial shows you how to use the top command through explaining the various parameters available and the content they display.