April 30, 2025 - 18:29
Linux SCP Command and Usage Image
Linux

Linux SCP Command and Usage

Comments

Hello again. We have a system on a local network. Sometimes we edit and activate certain files based on requests. Since it's an active system, we first test the changes on the test server, then send the modified files to other servers that use them.

So what if the number of servers to which the files will be copied is a little high? (By a little, I mean around 10.) The first thing that comes to mind is to download the files via FTP and set up an FTP connection to each one to upload them. Why bother so much? The servers are Linux. So if we use SCP, we get what we want.

SCP (Secure Copy) allows us to copy files and folders between two computers on a network. It uses the SSH service during the connection. SCP is very simple and short. After issuing the command, it connects, copies the file, and disconnects. In simple terms, its usage is as follows:

scp name_of_the_file_to_copy destination

SCP can communicate with remote computers, so we must indicate whether the file or the destination (or both) is on a remote machine by prefixing the remote location with 'username@host_name:'.

If we are copying from the remote computer to our own:

scp username@IPADDRESS:name_of_the_file_to_copy destination

If we are copying from our computer to the remote computer:

scp name_of_the_file_to_copy username@IPADDRESS:destination

If we are copying between remote computers:

scp username@IPADDRESS:name_of_the_file_to_copy username@IPADDRESS2:destination

That's it. After this step, you will be asked for the remote user's password, and once you enter it, your files will be copied. If you want to copy nested files and folders, you can use the (-r) parameter.

Let's give an example....

IP of the Source: 172.16.0.2
Location of the File: /home/aliosman/netopsiyon.txt
Target IP: 172.16.0.3

We logged into the server with IP 172.16.0.2 via SSH. Our command is as follows;

scp /home/aliosman/netopsiyon.txt root@172.16.0.3:/home/aliosman/

Now let's say we want to send a folder instead of a file. In this case, our command would be;

scp -r /home/aliosman/deneme root@172.16.0.3:/home/

We have another server. Its IP is 172.16.0.4. But its SSH port is not 22, it's 1230. In this case, we add a new parameter (-P) to the command.

scp -P 1230 -r /home/aliosman/deneme root@172.16.0.4:/home/

But I'm using Linux. So I don’t need to log into any server. Can I use SCP between two servers from my own computer? Let’s try it:

scp root@172.16.0.3:/home/aliosman/netopsiyon.txt root@172.16.0.4:/home/aliosman/

How do we send everything under /home/aliosman/ on the server with IP 172.16.0.2 to a different folder on the server with IP 172.16.0.3? With * :)

scp -r root@172.16.0.2:/home/aliosman/* root@172.16.0.3:/home/netopsiyon/

Now let’s log in to the server with IP 172.16.0.3 via SSH. Let's pull the file netopsiyon.zip from the server with IP 172.16.0.4.

scp root@172.16.0.4:/home/netopsiyon.zip /home/aliosman/

I guess that's enough examples. If you have any questions, or if you're thinking "you've lost it, where do you come up with this stuff?", feel free to leave a comment...

NOTE: You can also perform this process between real servers. The files and servers used in the commands are fictional.

Related Articles

Comments ()

No comments yet. Be the first to comment!

Leave a Comment