Managing Remote Systems in Oracle® Solaris 11.2

Exit Print View

Updated: July 2014
 
 

How to Copy a File Between Two Systems (scp)

  1. Ensure that you have permission to copy files on the target system.

    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

    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 Managing Secure Shell Access in Oracle Solaris 11.2 .


  2. Determine the location of the source and target.

    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 Accessing a Remote System by Using Secure Shell. 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.

  3. Copy the file or directory.
    $ scp [-r] [[user1@]hostname1:]file1 ... [[user2@]hostname2:]file2
    -r

    Use to recursively copy entire directories.

    user1, user2

    Login account to use on the remote host.

    hostname1, hostname2

    The names of the remote host from or to which the file is to be copied.

    file1

    The file name or directory name to be copied. Several source file names may be included on one command line.

    file2

    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