Cadastre-se agora para um orçamento mais personalizado!

How to use the scp command in Linux

jun, 14, 2023 Hi-network.com
Maskot/Getty Images

When you want to transfer a file from one Linux computer to another, you have several options: Some of these options are GUI tools, and some 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.

Also: The best Linux distros for beginners

At first glance, using scp might seem a bit confusing, but 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. 

What you'll need: To do this, all you'll need are two Linux machines. It doesn't matter what distribution you're using, but you will need 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.) This will become more clear in a moment.

Using the scp command

1. Push 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.

1. Pushing a file when your remote username is different.

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.

3. Pushing the file to a different remote directory

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.

4. Pulling a file from a remote machine

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.

Also: The best Linux laptops (and why you might want one)

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.

Jack Wallen: Here's how to...

How to get true window snapping in MacOSThe AGM 5 Pro might be the loudest Android phone everNitrux 2.4 Linux distro shows promiseTired of being tracked online? DuckDuckGo's Email Protection can help
  • How to get true window snapping in MacOS
  • The AGM 5 Pro might be the loudest Android phone ever
  • Nitrux 2.4 Linux distro shows promise
  • Tired of being tracked online? DuckDuckGo's Email Protection can help

tag-icon Tags quentes : Serviços & Software Sistemas Operacionais LINUX

Copyright © 2014-2024 Hi-Network.com | HAILIAN TECHNOLOGY CO., LIMITED | All Rights Reserved.