Here’s How You Can Copy Files over SSH Without Password

Here’s How You Can Copy Files over SSH Without Password

Typically when you use SSH to copy files from one server to another, you’re required to provide the password. The process goes something like this:
  • You use the secure copy command and name the original file and the destination file like this:
Code:
scp [options] original_file destination_file
  • You provide the remote username and destination path for copying
Code:
username@serverIP Address:path/to/file
  • Here’s the complete command to migrate a file from one Linux server to another:
Code:
scp –P 22 /home/test.txt vpshost@serverIP Address:/home/user/test.txt
If you need more information on the above command, here’s a brief explanation:
  • scp stands for secure copy command
  • -P is the port number
  • vphost is the user of the remote server
  • /home/user/test.txt is the destination where you’ll be moving the file to
The above process will require providing the remote server password.

How to Copy Files without a Password?

You can copy files from one Linux server to another by following these steps:
  • Execute this command at source machine (it will generate a file which you can view by running is command to .ssh directory):
Code:
ssh-keygen
  • Then run this command to copy the generated file to the remote server:
Code:
scp –P 22 /root/.ssh/id_rsa.pub vpshost@serverIP Address:/root/.ssh/
  • Now you must have created a directory called authorizedkey_3 at the remote server and placed it inside the /.ssh directory. Then run this command at the remote server:
Code:
cat .ssh/id_rsa.pub >> .ssh/authorized_keys
  • Execute this command to give permission to .ssh/authorized_keys folder:
Code:
chmod 600 .ssh/authorized_keys
  • Now you can test with copying files to the remote server and it shouldn’t ask for password. Use this command now:
Code:
scp –P 22 /home/test.txt vpshost@serverIP Address:/home/test.txt
So that’s how you copy files to a remote Linux server over SSH without the need for a password.
Author
kumkumsharma
Views
4,151
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from kumkumsharma

Top