【Scp】 command – Copy files to / from remote machine

In this series, we will introduce the basic commands of Linux from basic format to options, concrete execution examples in an easy-to-understand manner. This time, copy files to / from remote machine “scpCommand.

What is the scp command?

“Scp” is a command used when copying files between remote machine and local machine, or between remote machines. A similar command has “rcp (remote copy)”, but the scp command uses SSH for communication.

To execute the scp command, SSH connection must be possible, for example, “sshd (SSH daemon: SSH server program)” is running.

Format of scp command

scp [
] [Login name @ host name] path [login name @ host name] path

* [] Indicates optional arguments

Key options of the scp command

The main options of the scp command are as follows.

option meaning
-B Operate in batch mode (Do not ask for password input etc)
-l Limit Specify the used bandwidth in Kbit / sec
-p Maintain copy source time stamps and permissions
-P port number Specify the port number to be used for connection
-L user name Specify the user name to use for the connection
-i ID file Specify the public key file to be used for connection
-C Compress all communication
-c Encryption method Specify the method of encrypting communication (“3des” “blowfish” “des” can be specified)
-1 Use only SSHv1 (SSH protocol version 1)
-2 Use only SSHv2 (SSH protocol version 2)
-Four Use only IPv4
-6 Use only IPv6
-F configuration file Specify the SSH configuration file
-o configuration parameter Specify the SSH setting parameter (overrides the contents written in the setting file)
-q Do not display error messages or diagnostic messages (quiet mode)
-v Display debug messages (verbose mode)

[*] Note that “-l” (login name) of “ssh” command is “-L” and “-p” (port number) is “-P”

Copy files on the remote computer locally

scp Connection destination: path name“, Copy the file at the connection destination locally. Like the cp command, “scp Connection destination: path name Save destination“It is also possible to specify the storage location and the file name to save.

Specify the connection destination with the host name or IP address. For example, to copy “/etc/bash.bashrc” in “” to the current directory, “scp /etc/bash.bashrc”, save the place to “/ / Downloads /” If you do, specify “scp /etc/bash.bashrc ~ / Downloads /”.

You will be logged in with the current user name at the connection destination. If you want to login with a different name,-LOption or use the ssh command (The 80th) Similarly, “scp Login name @ Connected to: Path nameSpecify it as shown below.

If you have not made an SSH connection to the connection destination, the message “Are you sure you want to continue connecting (yes / no)?” Is displayed. If there is no mistake in the connection partner, enter “yes” and press the [Enter] key.

Next, the password prompt is displayed as “login name @ connected password:”. If it is set to log in using “key file”, enter the password set for the key, if not using the key file, enter the login password of the connection destination.

【※】 For ssh connection, connect using two key files “public key” and “secret key”. The key file is created with the “ssh-keygen” command, and the public key is managed by the server and the private key is managed by the user.

Command execution example

scp Connection destination: path name

scp Connection destination: path name Storage location

(Copy files on the remote computer locally) (Screen 1)


Screen 1
Copy “/etc/bash.bashrc” in “” and save it locally as “~ / Downloads bashrc.ubuntu”

After the second time, you can simply copy the password and copy it (Screen 2).


Screen 2
Connection confirmation message is not displayed after the second time

Copy local file to remote computer

If you want to copy files on your computer (local environment) to another computer (remote environment)scp file name Connected to: save pathSpecify it as shown below.

The “current directory” of the connection destination is the home directory of the login user. Therefore,scp file name login name @ connection destination:.“, The file is saved in the home directory of the user who used to login.

If there is the same name file in the save destination, it will be overwritten and saved. If you want to check the presence or absence of a file in advance, you can check it by executing ls command etc. in ssh (see 80th).

Command execution example

scp file name Connection destination: path name

(Copy local files remotely) (Screen 3)


Screen 3
Copied “tmp.txt” in the local current directory with scp to the remote “~ / Desktop”

Leave a Reply