How to use the scp command in Linux

When you want to transfer a file from one Linux computer to another, you have several options, some of which are GUI tools and some that are not. One of the most popular methods of transferring files also happens to be one of the more secure. That method is by way of the scp command.

Scp stands for Secure Copy and is part of the SSH tool, which nearly every Linux distribution includes out of the box. That means you don’t have to install any extra software to get this done.

And although at first blush using scp might be a bit confusing, it’s really not. I’m going to show you how it’s done, so you can push and pull files from one Linux machine to another. 

To do this, all you’ll need are two Linux machines. It doesn’t matter what distribution you’re using, but you will have to have user accounts on both machines (they don’t have to be the same user accounts, but you have to know the passwords for each account). It’ll be more clear in a moment.

Pushing a file from one machine to another

Let’s say you have the file zdnet_test on your local machine and you want to push it to another machine at IP address 192.168.1.30. To do this, log into the local machine and open a terminal window. Let’s say you have the same username on both the local machine and the remote machine. With that in mind, to push the zdnet_test file to the remote machine, you’d issue the command:

scp /path/to/zdnet_test 192.168.1.30:/home/USER

Where /path/to is the full path to the zdnet_test file and USER is the username on the remote machine.

You will be prompted for the user’s password and, upon successful authentication, the file will be copied.

Now, let’s say you have a different user on the remote machine. In that case, the command would be:

scp /path/to/zdnet_test [email protected]:/home/USER

Where /path/to is the full path to the zdnet_test file and USER is the username on the remote machine.

Again, you’ll be prompted for the user password before the file is copied.

You could also push that file to a different directory (other than the user’s home directory). The one caveat to this is the user must have permission to write to the directory in question. Let’s say you want to copy that file to a directory on the remote machine, named /data. As long as the remote user has access to that directory, the command would be:

scp /path/to/zdnet_test [email protected]:/data

Where /path/to is the full path to the zdnet_test file and USER is the username on the remote machine.

Once again, you’ll be prompted for the user password before the file is copied.

Pulling a file from a remote computer

Let’s say the zdnet_test file is on a remote computer and you want to copy it to the local machine. To do that, you’d issue the command:

scp 192.168.1.30:/path/to/zdnet_test /home/USER/zdnet_test

Where /path/to is the full path to the zdnet_test file and USER is the username on the remote machine.

And, yes, again you’ll be prompted for the user password before the file is copied.

Like with pushing a file, you can also define the remote user and change the path to where the file will be saved.

And that, my dear friends, is all there is to use the scp command on Linux. Enjoy this handy ability to push and pull files from one Linux machine to another, with the help of secure copy.

For all the latest Technology News Click Here 

 For the latest news and updates, follow us on Google News

Read original article here

Denial of responsibility! TechNewsBoy.com is an automatic aggregator around the global media. All the content are available free on Internet. We have just arranged it in one platform for educational purpose only. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, all materials to their authors. If you are the owner of the content and do not want us to publish your materials on our website, please contact us by email – [email protected]. The content will be deleted within 24 hours.