What is scp command in linux

Linux scp command

Computer Hope

On Unix-like operating systems, the scp command copies files over a secure, encrypted network connection.

scp stands for «secure copy.» It is similar to the standard Unix command, cp, but it operates over a secure network connection.

Description

The scp command can be thought of as a network version of cp. For example, you might use the following cp command:

cp /home/stacy/images/image*.jpg /home/stacy/archive

. which would copy all files in the directory images in user stacy‘s home directory whose name starts with «image» and ends in «.jpg» into the directory archive in her home directory.

Similarly, you could use the scp command:

. to upload those same files to the server myhost.com, using the login name stacy, into the remote directory /home/stacy/archive. scp will ask for stacy‘s remote password before initiating the upload.

Or, you could specify a remote location as the source location if you want to download files. For example,

scp [email protected]:/home/stacy/archive/image*.jpg /home/stacy/downloads

. would download all the files in the remote directory /home/stacy/archive on myhost.com whose name starts with «image» and ends in .jpg, into the local directory /home/stacy/downloads.

You can also specify a remote host as both the source and destination. For instance, the following command will transfer a file from one remote directory on myhost.com to another directory on the same server:

scp [email protected]:/home/user/dir1/file.txt [email protected]:/home/user/dir2

. while this command will transfer a file from one remote host to another:

scp [email protected]:/somedir/somefile.txt [email protected]:/anotherdir

Keep in mind that all scp transfers have the benefit of being secure: they are encrypted, like an ssh or sftp session.

Читайте также:  Creating shortcuts in linux

Copying files

scp copies files securely between hosts on a network. It uses ssh for data transfer, and uses the same authentication and provides the same security as ssh. Unlike rcp, scp will ask for passwords or passphrases if they are needed for authentication.

File names may contain a user and host specification to indicate that the file is to be copied to/from that host. Local file names can be made explicit using absolute or relative pathnames to avoid scp treating file names containing ‘:‘ as host specifiers. Copies between two remote hosts are also permitted.

Syntax

scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 . [[user@]host2:]file2

Options

-1 Forces scp to use protocol 1. This is an older protocol.
-2 Forces scp to use protocol 2. This is an older protocol.
-3 Copies between two remote hosts are transferred through the local host. Without this option the data is copied directly between the two remote hosts. This option also disables the progress meter.
-4 Forces scp to use IPv4 addresses only.
-6 Forces scp to use IPv6 addresses only.
-B Uses batch mode, operating without any interactive keyboard input. This means that scp cannot authenticate the session by asking the user to type in a password; therefore, a non-interactive authentication method is required. For an example of setting up non-interactive authentication, see Setting Up Public Key Authentication in our sftp documentation.
-C Enable compression, which passes the -C flag to ssh to enable compression of the encrypted connection.
-c cipher Selects the cipher to use for encrypting the data transfer. This option is directly passed to ssh.
-F ssh_config Specifies an alternative per-user configuration file for ssh. This option is directly passed to ssh.
-i identity_file Selects the file from which the identity (private key) for RSA authentication is read. This option is directly passed to ssh.
-l limit Limits the used bandwidth, specified in Kbit/s.
-o ssh_option Can be used to pass options to ssh in the format used in ssh_config. This is useful for specifying options for which there is no separate scp command-line flag. Valid options are:

The file name may use the tilde syntax to refer to a user’s home directory or one of the following escape characters: ‘%d‘ (local user’s home directory), ‘%u‘ (local username), ‘%l‘ (local hostname), ‘%h‘ (remote hostname) or ‘%r‘ (remote username).

This directive is useful in conjunction with nc and its proxy support. For example, the following directive would connect via an HTTP proxy at 192.0.2.0:

The default is «yes» (to send TCP keepalive messages), and the client will notice if the network goes down or the remote host dies. This is important in scripts, and many users want it too.

Examples

Copies the file myfile.txt to the remote host example.computerhope.com, using the username hope to log in.

Copies all files in the remote directory /home/hope on the remote host myremotehost.com into the local working directory.

scp -r [email protected]:/home/jeff/documents /home/jeff/downloads/documents

Copies all files in the remote directory /home/jeff/documents on the server myhost.com, including all subdirectories and the files they contain, into the local directory /home/jeff/downloads/documents.

Transfer the remote file /home/jeff/archive.zip on the remote host myhost.com as the user jeff into the local working directory, and limit the transfer to 100 kilobytes per second.

scp [email protected]:/files/file1.zip [email protected]:/archives

Copies the file in the remote directory /files/file1.zip on the remote host firsthost.com into the remote directory /archives on the remote host secondhost.com. You will be prompted to enter the passwords for the remote accounts [email protected] and [email protected], respectively. The transfer will go directly from one remote host to the other.

scp -3 [email protected]:/files/file1.zip [email protected]:/archives

Same as the above command, but rather than directly transferring the file from one remote host to the other, the transfer is routed through the local host.

rcp — Copy files to or from a remote system.
sftp — Conduct an interactive FTP session over a secure network connection.
slogin — Login to a remote system securely.

Источник

Оцените статью
Adblock
detector