|Skip Navigation Links|
|Exit Print View|
|Managing Remote Systems in Oracle Solaris 11.1 Oracle Solaris 11.1 Information Library|
The scp command copies files or directories between a local and a remote system or between two remote systems. You can use this command from a remote system (after logging in with the ssh command) or from the local system. The scp command uses ssh for data transfer. Thus, the scp command uses the same authentication and provides the same security as the ssh command.
Copy a file or directory from your local system to a remote system
Copy a file or directory from a remote system to your local system
Copy a file or directory between remote systems from your local system
The scp command, as a component of the ssh command, requires that you have either a user account or host key access to the target system. Consult Chapter 15, Using Secure Shell, in Oracle Solaris 11.1 Administration: Security Services for further information.
Caution - Both the cp and scp commands can overwrite files without warning. Ensure that file names are correct before executing the command.
With the scp command, you can specify the source (the file or directory to be copied) and the target (the location in which to copy the file or directory). You can shorten the path strings by using the tilde character (~) and the shell wildcard characters (*, ?, and so forth).
The tilde character (~) is expanded by all shell programs to be the current user's home directory. The current user is the user under which the shell is executing. If the home directory for the user jack is /export/home/jack, then for the user jack, ~/myfile.txt expands to /export/home/jack/myfile.txt.
This expansion also works for remote paths. If the user jack wants to copy a file from his home directory, then these three path descriptions are equivalent:
This expansion is also useful when referring to another user's remote home directory. In this case, you would include the user's name after the tilde character. For the user jack, mars:~jill/myfile.txt is equivalent to mars:/export/home/jill/myfile.txt, but it is shorter to type.
The scp command requires authentication. Depending upon the method of authentication used, you must have either an account on the target system, or an authorized public key on the target system. You should at least have read permission on the source system and write permission on the target system.
Caution - If you do not have an account on the target system, or if the target system is not configured to allow public keys, you will receive an authentication error. For example:
$ scp mars:/var/tmp/testdir/letter.txt . Permission denied (gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive)
Ensure that you have either a user account or public key access configured on the target system for authentication. See Secure Shell Authentication in Oracle Solaris 11.1 Administration: Security Services.
If you don't know the path of the source or target, you can first log in to the remote system with the ssh command, as described in Logging In to a Remote System (ssh). Then, navigate through the remote system until you find the location. You can then perform the next step without logging out of the remote system.
$ scp [-r] [[user1@]hostname1:]file1 ... [[user2@]hostname2:]file2
Use to recursively copy entire directories.
Login account to use on the remote host.
The names of the remote host from or to which the file is to be copied.
The file name or directory name to be copied. Several source file names may be included on one command line.
The destination file name or directory name.
Example 3-5 Using the scp Command to Copy a Remote File to a Local System
In this example, scp is used to copy the file letter.doc from the /home/jones directory of the remote system pluto to the working directory on the local system.
$ scp pluto:/home/jones/letter.doc . The authenticity of host 'pluto (192.168.56.102)' can't be established. RSA key fingerprint is b4:88:7b:cf:f5:23:d3:ad:0b:14:22:31:74:7b:6c:74. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.56.102' (RSA) to the list of known hosts. Password: letter.txt 100% |*****************************| 23 00:00 $
In this example, this is the first time the system pluto is accessed, hence, the RSA key fingerprint message.
Here, the “.” symbol at the end of the command line refers to the current working directory on the local system.
Example 3-6 Using the scp Command to Copy a Local File to a Remote System
In this example, scp is used to copy the file notice.doc from the home directory (/home/smith) of the local system earth to the /home/jones directory of the remote system, pluto.
$ scp notice.doc pluto:/home/jones Password: notice.doc 100% |*****************************| 0 00:00
Because no remote file name is provided, the file notice.doc is copied into the /home/jones directory with the same name.
In the following example, the scp operation from the previous example is repeated, but scp is executed from a different working directory on the local system (/tmp). Note the use of the “~” symbol to refer to the current user's home directory:
$ scp ~/notice.doc pluto:/home/jones Password: notice.doc 100% |*****************************| 0 00:00