How to transfer files from server to server Linux

🐹 Transfer files from server to server with tar

  • from server: tuenhai
  • to server: newserver

tuenhai and newserver are host names in SSH config file

tuenhai@desktop:~$ ssh tuenhai
tuenhai@ubuntu:~$ cd /
/$: tar -cJz all.xz home/tuenhai/  /home/tuenhai/a-folder

mv all.xz to public folder for download:

/$ sudo chown tuenhai:tuenhai all.xz
/$ sudo chmod 644 all.xz
/$ sudo mv all.xz home/tuenhai/

Login newserver and extract all.xz:

tuenhai@desktop:~$ ssh newserver
tuenhai@ubuntu:~$ cd /
/$ wget
/$ tar -xJf all.xz
/$ rm all.xz

Remove all.xz from old server:

tuenhai@desktop:~$ ssh tuenhai
tuenhai@ubuntu:~$ rm /home/tuenhai/

🚕 How to transfer small files from server to server quickly

sudoscp is a short script to allow copying files that are not readable or writable by your user between machines where you have sudo access but don't have access to log in as root over ssh. The servers does not need to be able to reach each other. The files to copy are not written to temporary files on either servers nor on the box the script is running from

Both servers need to be accessible by passwordless ssh (using public key auth). Both servers need to have tar and sudo installed. The sudo password needs to be the same on both servers

  • download sudoscp to local computer

    tuenhai@desktop:~/bin$ wget
    $ chmod 700 sudoscp
  • Transfer files from old server to new server quickly:

    tuenhai@desktop:~/bin$ ./sudoscp tuenhai newserver /etc/tuenhai/.ssh /etc/ssh/sshd_config /etc/sysctl.d/98-custom-rule* /etc/nginx/nginx.conf /etc/nginx/sites-*

results matching ""

    No results matching ""