From LQWiki
(Redirected from SCP)
Jump to: navigation, search

scp, secure copy, is a tool used to securely copy files over the network, by means of the SSH protocol. The sftp tool is similar. scp works very much like the Unix "cp" command:

scp <source> <destination>

If the source or destination of scp is a remote host, the syntax


is used. For example, to upload a file "foobar.txt" on a local computer to a remote host "" using the username "user" to the /var/www directory, the syntax is as follows:

$ scp foobar.txt

A password prompt follows

Password: <type the user's password here>

If the username is the same on the remote server it can be omitted:

$ scp hostname:/foo/bar/

If you are copying to your home folder on the remote system, the destination can be omitted:

$ scp hostname:

If you run SSH on a different port (that is, not the default port 22) and you need to scp then it can be done by:

$ scp -P <port> file user@host:

For example, if your ssh/scp is on port 2000 then:

$ scp -P 2000 filename.txt

the above command will connect to scp/ssh port 2000 and copy the file filename.txt to the remote user's home directory in the remote server.

If you use SSH key based authentication then when you scp, scp will not ask for user's password. It will copy your file to the remote server using your ssh private key. Example,

$ scp -i your_private_key file.txt remote_user@remote_host:

the above command will use your ssh private key and copy the file (file.txt) in the remote_user's home directory.

See also