- Basic Linux tutorials for beginner
- Linux basic concepts, installation and troubleshooting
- Linux administration
- Linux commands
- Linux network tutorials
- Linux security tutorials
- Linux software configuration
- Linux desktop tutorials for beginner
- Collection of Linux tips
Linux scp command - copy file and directory from remote computer
Submitted by jinlusuh on Tue, 02/03/2009 - 11:43
There is a secure copy command in Linux that you can use to copy file or directory from remote computer. This is definitely a good option if you are going to transfer data remotely and need an encryption. The command we are talking about is the Linux scp command. We can run scp command from any Linux distribution's command line terminal.
The Linux scp comes together with ssh server package. So, to use scp command, the remote machine or the Linux server must have ssh server installed and running. If you want to install scp server in Ubuntu, you have to install ssh server package. The install ssh in Ubuntu tutorial describes all about ssh installation if you need help. For just scp installation in Ubuntu, you can see an example below. scp server is already in your system if you are using Slackware because scp included in Slackware default installation.
How to install scp in Ubuntu
As we mention earlier, scp included in the ssh package, so we'll use apt-get to install ssh package:
If somehow your Slackware server doesn't have ssh server, you can install it online as Ubuntu server above using slackpkg command. That's it. Now you have scp in your Ubuntu system. To start using scp to transfer file or directory, let's see the command's usage.
Linux scp command syntax and examples
The Linux scp command is a very useful tool for a remote copy. It is a better option than rcp because it uses encryption just like ssh program. In fact, it uses ssh for data transfer authentication. That means, you certainly need to provide login name and password of the target/destination computer. To start using Linux scp program, let's look at the most important part, the command syntax or command format.
This is the Linux scp command syntax to send file or directory to a remote computer:
scp -r [/path/filename] [login name@ip address] : .
This is the Linux scp command syntax to retrieve file or directory from a remote computer:
scp -r [login name@ip address] : [/path/filename] .
Here are the meaning of scp command options:
- -r = recursively copy entire directory
- . = current directory
'/path/filename' is the complete directory path and name where the file resides.
'login name@ip address ' is the target/destination computer. You have to provide your login name and ip address and will be asked for user password.
Dot (.) at the end of the command means the files will be copied to the current directory. Of course you can change the destination to any directory you wish, just type the full path and directory name to replace the dot(.).
You can find more details in the scp manual page by invoking man scp from Linux command line terminal, which is recommended, if you could at least read it once to get a better understand of the command.
Now that you already understand how scp command works, let's see some actual examples taken from Ubuntu client.
Example on how to send file to a remote computer with scp command in Ubuntu Linux using ip address:
The scp command example above shows I am sending a file named UserManual.pdf from my computer to a remote computer with an ip address 192.168.1.6. The file UserManual.pdf must be in our home directory. If not, please provide a complete directory path. The file will be saved in luzar's home directory. I specified the user name which I want to login with (remember that we need to provide a valid username and password) and enter the password afterward.
Here is the example on how to retrieve file from a remote computer using scp command in Linux. This time we are using remote server's hostname:
The scp command example above shows that I was retrieving a file named netfilter.pdf from a remote computer with an ip address 192.168.1.6. Notice that this time I used a full directory path to the file which I want to get.
We can also use scp command to transfer multiple files at once to a remote computer. See the example below:
We can also use wild card with scp command such as * to copy all files. If you feel that copying the whole directory is a better idea, here is an example of scp command used to transfer a directory to a remote computer:
We use scp -r option in the example above to recursively copying a directory named folder.
You can also use scp command to transfer file or directory to other Linux computer using Windows operating system. Get Putty to login to the Linux server and use scp to copy file or directory to a remote computer (Linux computer) just as examples above.
Finally, if for any reason you need to uninstall scp from you Ubuntu server, you can do so by removing ssh package. You can use apt-get remove ssh command or apt-get purge ssh command. You can also use autoremove option like the example below:
That cover almost all about how to use Linux scp command to copy files or directory from remote computer. Now you should understand that scp is about transferring files or directory to or from a remote computer. It is similar to the ftp protocol. In fact, scp is a perfect choice to transfer an important file because it supports data encryption. If you prefer ftp protocol, you can check ftp client guide for ftp commands tutorial, install and configure proftpd in Ubuntu tutorial and install and configure vsftpd in Slackware Linux on how to install ftp server in your Linux.
Back to Linux basic commands main page.