Creating ssh connection between two servers and copying files between them
Step 1: Create SSH key
goto ~/.ssh folder and execute ssh-keygen
Step 2: Copy the public key to the other server
Execute the following to copy the public key to the remote machine
ssh-copy-id -i ~/.ssh/mykey user@host
where mykey is the key you generated in step 1.
Note:
For the first time, you will have to use password in order to access to the shell in the remote machine.
And done.
Step 3: Copy files via SCP
In order to copy files from server to local,
$ scp -r user@xexample.com:/folder/backups/2021-01-21/ bak
In order to copy files from local to server,
$ scp -r file_to_copy.ext user@your_domain.com:/path/to/folder/in/remote/server