Using File Transfer on Linux | Towards AI

How to use the SCP Command for File Transfer

SCP (secure copy) command in Linux can be confusing, let me make this a bit easier for you

Garima Nishad
Towards AI
Published in
4 min readAug 6, 2019

--

In this blog post, I’m going to show you how you can use the SCP command to copy your files or directories from your local machine to a remote server. So let’s say I have a remote server( shown below):

This one is my local machine,

Now let’s say and I want to transfer the file from my local machine to a remote server. So, first of all, let’s see what are the options we have with the SCP command by typing “scp” in the terminal.

This will show you all the options which you can use with the SCP:

As documentation states that

  • -c cipher
    Selects the cipher to use for encrypting the data transfer. This option is directly passed to ssh(1).
  • -F ssh_config
    Specifies an alternative per-user configuration file for ssh. This option is directly passed to ssh(1).
  • -i identity_file
    Selects the file from which the identity (private key) for public-key authentication is read. This option is directly passed to ssh(1).
  • -l limit
    Limits the used bandwidth, specified in Kbit/s.
  • -o ssh_option
    It can be used to pass options to ssh in the format used in ssh_config.

We may not use all these complex commands if we simply want to transfer the file. In that case, we just need to give the username and the host IP and then the file name.
For example, let’s say I have a folder called “idd” in one of my Desktop folders.

So I’m going to just CD to my folder first of all and then I will transfer this idd folder to the server from my home directory.

So I have a folder named “idd1” which I’m gonna copy to the remote server.

so we will use an SCP command and the IP of this remote server so to know the IP of the remote server you just say if config and then press enter

The IP address of the remote server is the one written right beside “inet” and then we also need the user so username in my case is “garima” which can be different in your case.

So now in your SCP command write your file name, so just give the file name in my case its “idd” and then the hostname which is “garima” in my case and then @ the IP address of the remote server.

Please note that if your file is a normal file you don’t need to add -r , it is only used for copying folder or directory

So, in whatever folder you want to transfer your files you just need to give the path of that after the colon (:) so, for example, I want to just transfer my files to the alice directory, then press enter.

scp -r idd1 garima@10.5.0.184:/home/garima/alice

For the first time, it will ask you “are you sure you want to continue connecting?” you can just say yes for the first time and then press ENTER and then it’s going to need your remote server's password so the password you use to log into this remote server. Just enter your password then this file would be transferred.

There you have it, your files will be transferred in a flash.

--

--

A Machine Learning Research scholar who loves to moonlight as a blogger.