Sunday, April 15, 2012

Scp command in linux (Secure copy)

Do you need to copy some files from on Linux machine to other or from one Linux use to other user??? so here is the Linux command which you can use to copy files from one Linux machine to other only if you know the password :) for sure, as using this command you can copy file without need of any messenger of such kind of utility so i am giving this any way you can always install "iptux" using which you can transfer files inside LAN.
Any how lets talk about the command which I was talking the command is called SCP which means secure copy.

Here is the explanation about the command :


scp - secure copy (remote file copy program)

Syntax

scp [-pqrvBC46 ] [-ssh_config ] [-program ] [-port ] [-cipher ] [-identity_file ] [-ossh_option ] [[user@ ] host1 : file1 ] [... ] [[user@ ] host2 : file2 ]



Some examples :


Copy the file "Examplefiletocopy.txt" from a remote host to the local host
$ scp your_username@remotehost.edu:Examplefiletocopy.txt /some/local/directory
Copy the file "Examplefiletocopy.txt" from the local host to a remote host
$ scp Examplefiletocopy.txt your_username@remotehost.edu:/some/remote/directory
Copy the directory "dirtocopyrecursively" from the local host to a remote host's directory "bar"
$ scp -r dirtocopyrecursively your_username@remotehost.edu:/some/remote/directory/bar
Copy the file "Examplefiletocopy.txt" from remote host "rh1.edu" to remote host "rh2.edu"
$ scp your_username@rh1.edu:/some/remote/directory/Examplefiletocopy.txt \
your_username@rh2.edu:/some/remote/directory/
Copying the files "Examplefiletocopy.txt" and "Examplefiletocopy2.txt" from the local host to your home directory on the remote host
$ scp Examplefiletocopy.txt Examplefiletocopy2.txt your_username@remotehost.edu:~
Copy the file "Examplefiletocopy.txt" from the local host to a remote host using port 2264
$ scp -P 2264 Examplefiletocopy.txt your_username@remotehost.edu:/some/remote/directory
Copy multiple files from the remote host to your current directory on the local host
$ scp your_username@remotehost.edu:/some/remote/directory/\{a,b,c\} .

$ scp your_username@remotehost.edu:~/\{Examplefiletocopy.txt,Examplefiletocopy2.txt\} .
scp Performance
By default scp uses the Triple-DES cipher to encrypt the data being sent. Using the Blowfish cipher has been shown to increase speed. This can be done by using option -c blowfish in the command line.
$ scp -c blowfish some_file your_username@remotehost.edu:~
It is often suggested that the -C option for compression should also be used to increase speed. The effect of compression, however, will only significantly increase speed if your connection is very slow. Otherwise it may just be adding extra burden to the CPU. An example of using blowfish and compression:
$ scp -c blowfish -C local_file your_username@remotehost.edu:~

Some More

To copy files between two machines, say yourmachineipaddress and paddressofcomputerwhereyouwanttocopyfile, sit at yourmachineipaddress and use the following command:
scp * ipaddressofcomputerwhereyouwanttocopyfile:

Simple as that! Assuming you are the same user id on both machines, this will copy all files in the current directory to your home directory on the destination machine, ipaddressofcomputerwhereyouwanttocopyfile. The first thing the command will do, though, is ask you for your password on the remote system - once you supply that, then you'll see the files copied, with progress bars.

Now, if you want to copy only some files, e.g. all txt files, use a standard wildcard, like this:
scp *.txt ipaddressofcomputerwhereyouwanttocopyfile:

Suppose you want to copy them to a destination directory other than your home directory, use:

scp *.txt ipaddressofcomputerwhereyouwanttocopyfile:/home/username/directory

Of course, you have to have write permission on the target directory.

Suppose you want to copy files from the other machine back to the one you're on - then use this syntax:
scp ipaddressofcomputerwhereyouwanttocopyfile:*.txt .

If you have a DNS or hosts file set up, then you can (and should) use hostnames in the command, like this:

scp Download/* Ipaddressofcomputerwhereyouwanttocopyfile:/home/shashwat/Download

This will copy the contents of the Download subdirectory (of the current directory) on this machine, to the directory /home/shashwat/Download on the machine Ipaddressofcomputerwhereyouwanttocopyfile.


Note : for this command install openssh on your machine using command : sudo apt-get install ssh



No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

#Intel #Core #i9 #Processors: A Breakdown

Intel Core i9 Processors: A Breakdown Intel's 14th Gen Core i9 series offers a range of processors designed for various use cases. Her...