Search This Blog

Tuesday, May 13, 2014

Copy files from Local to remote using ssh

In order to copy files from local to a remote system using ssh, there should be an  authorized user with a pem file. And also for that particular user in the remote system, there should be proper permissions for the destination.

Remote System

  • Login to the remote server using putty or through powershell.
  • Navigate to the destination folder
            > cd <destination>
  • Change the permissions using the below command
            > chmod -R 777 *

Local System

  • Open command prompt
  • Use scp command to copy the required files
           > scp -i <pem file path> <files to copy> <user@remote server>:<destination folder>
  • Using the above command the files will be copied and the permission are set as if it is a new file.
  • If it is required to copy the file along with its history and permissions, then use -p option
           > scp -p -i <pem file path> <files to copy> <user@remote server>:<destination folder>

Remote system - check file permissions

  • Now login to your remote system and check if the files are copied properly or not.
  • Some time there will not be proper permissions to the files that are copied. In that case, change the owner and the read/write permissions as per the requirement. This can be done only by the root user
  • If you are logged in as different user other than root, logout the user
            >logout
  • Sudo as a root user
            >sudo su
  • Change the ownership
            >chown owenrname:groupname <target files>
  • Change the permissions
             >chmod -R 777 <target files>

No comments:

Post a Comment