How to Remotely Copy Files Over SSH Without Entering Your Password?

We can easily copy the files from one Linux machine to another using SSH, for which you can see the example here – 

Copy Files Over SSH
We can use the secure copy command, which is easy to use, and this is the format of this command – 

scp [options] original_file destination_file

You will need to use the remote username and destination path while copying the file.

username@serverIP Address:path/to/file

You can use the server IP address or the resolvable hostname.
The command mentioned below can be used to migrate a file from one Linux machine to a remote Linux machine – 

scp –P 22 /home/test.txt vpshost@serverIP Address:/home/user/test.txt

Below is the explanation of the above command – 

scp : Secure Copy

-P  : port number. Here, we have used the default port 22 for the SSH. If you have configured SSH to another port, you will need to use the same port

vpshost : It is a user of the remote server.

/home/user/ : Destination where we will move the file on the remote server.

You can easily copy the files to the destination remote server using the above command, but you will need to enter the remote server password to complete the copying.

Copy Files Over SSH without a Password

  1. Run the below command in the source machine.
    You can refer to generate SSH key for more details.


2. You can run the ls command to the .ssh directory to view the generated file. id_rsa is your private key, and the is your private key.

3. Copy the public file to the remote server using the scp command.
    But before that, create the authorizedkey_2 directory in the remote server inside the /.ssh directory.

scp –P 22 /root/.ssh/ vpshost@serverIP Address:/root/.ssh/

4. Now run the below-given command in your remote server – 

cat .ssh/ >> .ssh/authorized_keys

5. Give the below-mentioned permission to the .ssh/authorized_keys folder – 

chmod 600 .ssh/authorized_keys 

6. Finally, test copying files without a password from the source to the remote server; you will see it will not ask for the password.

scp –P 22 /home/test.txt vpshost@serverIP Address:/home/test.txt


Was this answer helpful?

« Back